获取post请求的几种常见方式
Posted 4amljw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取post请求的几种常见方式相关的知识,希望对你有一定的参考价值。
通常从http post请求获取数据的方法如下:
1.request.getInputStream()
2.request.getReader()
3.request.getParameterMap()系列
4.通过spring框架中的RequestBody或RequestParam
public static String req2RawString(HttpServletRequest request)
StringBuilder sb = new StringBuilder();
BufferedReader reader = null;
try
reader = request.getReader();
String line;
while ((line = reader.readLine()) != null)
sb.append(line).append(‘\n‘);
if (sb.length() > 1)
sb.replace(sb.length() - 1, sb.length(), "");
catch (IOException e)
logger.info("RequestUtil,IOException:" + e);
finally
if (reader != null)
try
reader.close();
catch (IOException e)
logger.info("RequestUtil,IOException:" + e);
String str = sb.toString();
logger.info("Request Result:" + str);
return str;
原文:https://blog.csdn.net/dengbixuan/article/details/73556970
以上是关于获取post请求的几种常见方式的主要内容,如果未能解决你的问题,请参考以下文章