zl程序教程

您现在的位置是:首页 >  其他

当前栏目

获取post请求的几种常见方式详解编程语言

编程语言 详解 获取 方式 常见 请求 几种 post
2023-06-13 09:11:47 时间

通常从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;

17389.html

c