HttpServletRequest request 可以通过 request.getParameter("") 得到请求头参数
却不能修改 请求的参数 ,但zuul 的过滤器可以
//zuul 过滤器中:
RequestContext ctx= RequestContext.getCurrentContext();//获取当前的 上下文对象
HttpServletRequest request = ctx.getRequest();//获取 request
//获取请求头参数 post请求体的拿不了
request.getParameterMap(); //必须加这句 不然ctx.getRequestQueryParams()失败
Map<String, List<String>> requestQueryParams = ctx.getRequestQueryParams();//参数键值对map
System.out.println(requestQueryParams);
//添加 修改请求头参数 请求体的改不了
//如果一开始请求头里没参数 那么requestQueryParams为空
if (requestQueryParams==null) requestQueryParams=new HashMap<>();
List<String> arrayList = new ArrayList<>();
arrayList.add("100"); //添加values
requestQueryParams.put("userId", arrayList); //把参数键值对放入map
currentContext.setRequestQueryParams(requestQueryParams);//重新设置请求头所含有的参数
参考链接:https://blog.csdn.net/qq_31122833/article/details/83022904