以流的方式读取url中的参数

@RequestMapping(value = "/userPreference",produces="application/json;charset=utf-8")
@ResponseBody
public String userPreference(HttpServletRequest request) {
InputStreamReader reader = null;
String json = "";
try {
request.setCharacterEncoding("UTF-8");
reader = new InputStreamReader(request.getInputStream(), "UTF-8");
char[] buff = new char[1024];
int length = 0;
while ((length = reader.read(buff)) != -1) {
String x = new String(buff, 0, length);
System.out.println(x);
json = json + x;
}
}
catch (IOException e) {
e.printStackTrace();
}


JSONObject js = JSONObject.parseObject(json);
System.out.println(js);
String uid = js.getString("uid");

}
原文地址:https://www.cnblogs.com/foreverstudy/p/10442645.html