账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    axios的withCredentials问题
    29
    0

    问题描述

    我想要跨域带上cookies,为什么withCredentials: true不起作用?

    问题出现的环境背景及自己尝试过哪些方法

    我尝试过axios.defaults.withCredentials = true可以起作用。
    但是为什么单独配置,没有作用?

    相关代码

    axios.post('http://101.132.138.141:8888/service/pageUsers', objectToForm({
            'currentPage': '1',
            'pageSize': '10',
            'token': '7e987daa-6c84-46d2-be26-f345dfaed8a7',
        }), {
            // 单独配置
            withCredentials: true
        })
        .then(function(res) {
            console.log(res.data);
        })
        .catch(function(err) {
            console.error(err);
        });

    实际看到的错误信息又是什么?

    已拦截跨源请求:同源策略禁止读取位于 http://101.132.138.141:8888/service/pageUsers 的远程资源。(原因:CORS 头缺少 'Access-Control-Allow-Origin')。

    后端已经设置了CORS头,但是因为没有附带上cookies,所以被拦截器拦截了。

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • o﹎.熟悉 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部