http请求的header body

来源:互联网 发布:开淘宝店需要注意哪些 编辑:程序博客网 时间:2024/04/29 17:02
在http请求中,有Header和Body之分,读取header使用request.getHeader("...");

读取Body使用request.getReader(),但getReader获取的是BufferedReader,需要把它转换成字符串,下面是转换的方法。

public static String getBodyString(BufferedReader br) {
  String inputLine;
      String str = "";
    try {
      while ((inputLine = br.readLine()) != null) {
       str += inputLine;
      }
      br.close();
    } catch (IOException e) {
      System.out.println("IOException: " + e);
    }
    return str;
 }

1 0