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即可,或者把請求頭里別用"_"