在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实例代码的全部内容了,希望对大家有所帮助,多多支持移动技术网~
如对本文有疑问, 点击进行留言回复!!
HashMap、Hashtable、ConcurrentHashMap三者间的异同
解决RecycleView 中Item包含Edittext时,滑动view复用导致数据错乱的问题
多线程、同步工作原理、死锁案例、Lock接口、线程的生命周期的讲解及实现
网友评论