zuul的过滤器filter的run方法里面写如下
InputStream in = null; try { in = ctx.getRequest().getInputStream(); String body = StreamUtils.copyToString(in, Charset.forName("UTF-8")); JSONObject json = JSONObject.parseObject(body); json.put("id", id); String newBody = json.toString(); final byte[] reqBodyBytes = newBody.getBytes(); ctx.setRequest(new HttpServletRequestWrapper(request){ @Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStreamWrapper(reqBodyBytes); } @Override public int getContentLength() { return reqBodyBytes.length; } @Override public long getContentLengthLong() { return reqBodyBytes.length; } }); } catch (IOException e) { e.printStackTrace(); }