前言
转载自:http://www.mamicode.com/info-detail-2517079.html
ps:只能获取一次,第二次就获取不到了
原因这篇文章讲的很清楚:https://www.cnblogs.com/yepei/p/7011081.html
解决办法:
参考:
- https://blog.csdn.net/football0/article/details/90442635
- https://www.cnblogs.com/flgb/p/10976751.html
- https://www.cnblogs.com/a393060727/p/6141295.html
代码
String param= null;
try {
BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));
StringBuilder responseStrBuilder = new StringBuilder();
String inputStr;
while ((inputStr = streamReader.readLine()) != null)
responseStrBuilder.append(inputStr);
JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
param= jsonObject.toJSONString();
System.out.println(param);
} catch (Exception e) {
e.printStackTrace();
}