• 获取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(' ');
                  }
                  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 

  • 相关阅读:
    异常处理
    PAT——1048. 数字加密
    PAT——1047. 编程团体赛
    PAT——1046. 划拳
    PAT——1045. 快速排序(25)
    PAT——1044. 火星数字
    PAT——1043. 输出PATest
    PAT——1042. 字符统计
    PAT——1041. 考试座位号
    PAT——1040. 有几个PAT
  • 原文地址:https://www.cnblogs.com/4AMLJW/p/xdfg5654hjghg.html
Copyright © 2020-2023  润新知