/**
* @Description: requestBody的处理
* @userName: jiangyu
* @date: 2015年11月11日 上午9:15:38
* @param request
* @param response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
{
try
{
request.setCharacterEncoding("UTF-8");
int size = request.getContentLength();
InputStream is = request.getInputStream();
byte[] reqBodyBytes = readBytes(is, size);
//获取请求body中的内容
String res = new String(reqBodyBytes);
request.setAttribute("fetchUrl", res);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static final byte[] readBytes(InputStream is, int contentLen)
{
if (contentLen > 0)
{
int readLen = 0;
int readLengthThisTime = 0;
byte[] message = new byte[contentLen];
try
{
while (readLen != contentLen)
{
readLengthThisTime = is.read(message, readLen, contentLen - readLen);
if (readLengthThisTime == -1)
{// Should not happen.
break;
}
readLen += readLengthThisTime;
}
return message;
}
catch (IOException e)
{
// Ignore
e.printStackTrace();
}
}
return new byte[] {};
}
获取requestBody中的内容
最新推荐文章于 2024-07-12 10:00:52 发布