zoukankan      html  css  js  c++  java
  • 记一次后端拿不到自定义请求头的经历

    1.公司项目用户账号密码登录,使用了rsa加密,针对不同版本做了不同需求,不影响之前的版本,

    使用了自定义请求头“yx_version”

    //拦截器设置全局请求token
    Vue.http.interceptors.push((request, next) => {
            if(localStorage.getItem('userInfo')!="null"&&localStorage.getItem('userInfo')!=""&&localStorage.getItem('userInfo')!=null){
                request.headers.set('Authorization',JSON.parse(localStorage.getItem('userInfo')).token); //设置请求头
                // request.headers.set('Content-Type','application/json;charset=UTF-8'); //设置请求头
            }
            
            request.headers.set('us','web'); //设置web后台标识
            request.headers.set('yx_version','2.10'); //rsa加密版本
            //设置请求时间
            let timeout;
            // 如果某个请求设置了_timeout,那么超过该时间,会终端该(abort)请求,并执行请求设置的钩子函数onTimeout方法,不会执行then方法。
            if (request._timeout) {
                timeout = setTimeout(() => {
                    if(request.onTimeout) {
                        request.onTimeout(request);
                        request.abort()
                    }  
                }, request._timeout);
            }
            next((response) => {
                clearTimeout(timeout);
                return response
            })
    })

    2.后台本地测试是可以拿到,部署到服务器后拿不到

    3.本地没问题,为什么发布之后就有问题,不是跨域问题,那就是环境问题,第一个要检查的就是nginx,因为本地没有nginx,服务器上有

    解决方法

    nginx里面有个underscores_in_headers 配置,默认是off,这个配置是默认忽略掉请求header里
    面的"_"的,改成on即可,或者把请求头里别用"_"
  • 相关阅读:
    Python编程题24--回文数
    Python编程题23--移动零
    Python编程题22--只出现一次的数字
    Python编程题21--每日温度
    Python编程题20--最大子序和
    Python编程题19--比特位计数
    推荐系统中对比实验工具--伯乐bole
    pytorch中反向传播的loss.backward(retain_graph=True)报错
    win10彻底禁止自动更新(家庭版操作)
    linux使用清华源安装工具,切换清华源
  • 原文地址:https://www.cnblogs.com/lizhao123/p/13606204.html
Copyright © 2011-2022 走看看