首页 > 编程 > Java > 正文

java读取http请求中的body实例代码

2019-11-26 13:47:18
字体:
来源:转载
供稿:网友

在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; }

以上就是小编为大家带来的java读取http请求中的body实例代码的全部内容了,希望对大家有所帮助,多多支持武林网~

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表