java request获取body_【Java】java获取request body

//方式一

public staticString ReadAsChars(HttpServletRequest request)

{

BufferedReader br= null;

StringBuilder sb= new StringBuilder("");try{

br=request.getReader();

String str;while ((str = br.readLine()) != null)

{

sb.append(str);

}

br.close();

}catch(IOException e)

{

e.printStackTrace();

}finally{if (null !=br)

{try{

br.close();

}catch(IOException e)

{

e.printStackTrace();

}

}

}returnsb.toString();

}//方法二

public static voidReadAsChars2(HttpServletRequest request)

{

InputStream is= null;try{

is=request.getInputStream();

StringBuilder sb= newStringBuilder();byte[] b = new byte[4096];for (int n; (n

你可能感兴趣的:(java,request获取body)