java读取http请求中的body
生活随笔
收集整理的這篇文章主要介紹了
java读取http请求中的body
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
來源:http://blog.sina.com.cn/s/blog_49cc672f01018fik.html
在http請求中,有Header和Body之分,讀取header使用request.getHeader("...");
讀取Body使用request.getReader(),但getReader獲取的是BufferedReader,需要把它轉(zhuǎn)換成字符串,下面是轉(zhuǎn)換的方法。
??????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;
?}
總結(jié)
以上是生活随笔為你收集整理的java读取http请求中的body的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql驱动jar包下载
- 下一篇: 社保定点医疗机构是什么