spring cloud zuul 传递 header

        HttpSession session = request.getSession(false);
        if (session != null) {
            Object userAttribute = session.getAttribute(UserConstant.SESSION_KEY);
            if (userAttribute != null) {
                LoginUser user = JSON.parseObject(userAttribute.toString(), LoginUser.class);
                Integer userId = user.getId();
                Integer userInvoiceId = user.getUserInvoiceId();
                RequestContext ctx = RequestContext.getCurrentContext();
                if (userId != null && userInvoiceId != null) {
                    ctx.addZuulRequestHeader(AuthConstant.USER_ID, userId.toString());
                    ctx.addZuulRequestHeader(AuthConstant.INVOICE_ID, userInvoiceId.toString());
                    log.info("有身份认证信息 userId:{} userInvoiceId:{} ", userId, userInvoiceId);
                    return null;
                } else {
                    log.warn("session中的用户信息错误 userId:{} , userInvoiceId:{}", userId, userInvoiceId);
                    return null;
                }
            }
        }

最近在做一个项目时,发现在网关中调用和在子系统中调用request.getRequestURL()所得到的请求url是不一样的,在网关中得到的是通过域名访问的地址,而在子系统中得到的是网关发起的子系统的真是IP地址,现在想在系统中得到原始的请求地址,需要把参数从网关传给子系统,找个好多方法,最后只有这个方法可行(也许有别的方式)

网关

RequestContext ctx = RequestContext.getCurrentContext();
ctx.addZuulRequestHeader("original_requestURL",request.getRequestURL().toString());
子系统

request.getHeader("original_requestURL")
---------------------
作者:zhang_zining
来源:CSDN
原文:https://blog.csdn.net/zhang_zining/article/details/79636602
版权声明:本文为博主原创文章,转载请附上博文链接!

https://blog.csdn.net/u012903926/article/details/81510272

SpringCloud 网关服务中添加网关请求头内容,有时候需要添加中文内容,这时候在业务服务获取的时候就出现了乱码,楼主尝试了各种转码均无效,只有URLEncoder编码解码可以解决这个问题。
URLEncoder.encode(str, “UTF-8”);//编码 在网关添加内容是编码
URLDecoder.decode(str, “UTF-8”);//解码 微服务获取时解码
---------------------
作者:茉么乔
来源:CSDN
原文:https://blog.csdn.net/sinat_35880552/article/details/82698311
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/softidea/p/10679746.html