首页 > 开发 > Java > 正文

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

2024-07-13 10:00:37
字体:
来源:转载
供稿:网友

在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实例代码的全部内容了,希望对大家有所帮助,多多支持VeVb武林网~


注:相关教程知识阅读请移步到JAVA教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表