欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

解析HttpServletRequest 的body 内容

程序员文章站 2024-02-04 21:07:16
...
  public String getChars(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();
        }
      }
    }
    return sb.toString();
  }