spring接到浏览器传来的post请求 所传进来的参数都在request里
1 @RequestMapping(value = PROXY_URL, method = RequestMethod.POST, produces = PRODUCES)2 public Object proxy(final HttpServletRequest request, final HttpServletResponse response) {3 String json = "";4 json = new String(readInputStream(request.getInputStream()), "UTF-8");
5 }
此时debug查看request.getInputStream()的值是全部请求信息 但是并非我们想要是参数
所以我们要对结果解析
readInputSream()是解析方法
1 public static byte[] readInputStream(InputStream inStream) throws Exception { 2 ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); 3 byte[] buffer = new byte[1024]; 4 boolean var3 = false; 5 6 int len; 7 while((len = inStream.read(buffer)) != -1) { 8 outSteam.write(buffer, 0, len); 9 }10 11 outSteam.close();12 inStream.close();13 return outSteam.toByteArray();14 }
inStream.read(buffer)读取数据赋值给buffer
outSteam的结果就是我们想要的数据了
注意 这里的json格式的数据是前端定义好传进来的 和后台对io流解析无关