/**
* 读取请求参数
* @author 向蓬
* @date 2016-6-29上午10:56:28
* @param request
* @return
* @throws IOException
* String
*/
public static String readRequestBody(HttpServletRequest request){
InputStream inputStream = null;
BufferedInputStream buf = null;
StringBuffer requestJsonBuffer = null;
try {
inputStream = request.getInputStream();
buf = new BufferedInputStream(inputStream);
byte[] buffer = new byte[1024];
requestJsonBuffer = new StringBuffer();
int a = 0;
while ((a = buf.read(buffer)) != -1){
requestJsonBuffer.append(new String(buffer, 0, a, "UTF-8"));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
//关闭连接
if (null != buf){
try {
buf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != inputStream){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null == requestJsonBuffer ? null : requestJsonBuffer.toString();
}
java解析http+json数据包
最新推荐文章于 2022-01-12 16:42:43 发布