axios无跨域设置withCredentials无效?

发布于 2022-09-11 16:58:01 字数 2285 浏览 9 评论 0

问题描述

代码如下,设置了withCredentials

在第一层axiosres里面查看堆栈,
发现res.headersset-cookie属性里面的JSSESIONIDPath/authcas/

而在第二以及第三层的res.headers里面发现不断被设置set-cookie属性,而且res.request._header里面发现请求根本没有携带cookie

经过检查Cookie的确不存在跨域和Path路径不对应问题,PostMan以及JavaHttpClient测试均没有问题。
本应该被携带上Cookie却没有携带上,请问问题出在哪里?谢谢

function getCaptcha(username, password) {
    const map = new Map;
    map.set('password', password)

    const axios = Axios.create({
        headers: {
            'X-Requested-With': 'XMLHttpRequest'
        },
        baseURL: 'https://xxxx.xxxx.edu.cn',
        withCredentials: true
    })
    axios
        .get('/authcas/getCaptcha?service=http://xxxxxx.action')
        .then(res => {
            const body = res.data
            const ltLabel = body.match(/<input\s+type="hidden"\s+name="lt"\s+id="lt"\s+value="([a-zA-Z0-9.\-]+)"\s+\/>/)
            if (ltLabel.length >= 2) map.set('lt', ltLabel[1])
            else throw new Error()

            const exeLabal = body.match(/<input\s+type="hidden"\s+name="execution"\s+id="execution"\s+value="(\w+)"\s+\/>/)
            if (exeLabal.length >= 2) map.set('execution', exeLabal[1])
            else throw new Error()

            Axios
                .all([
                    axios.get(`/authcas/security/evaluate?userId=${username}`),
                    axios.get('/authcas/captcha')
                ])
                .then(() => {
                    const t = Math.random()
                    Axios
                        .all([
                            axios.get(`/authcas/captcha/master?${t}`),
                            axios.get(`/authcas/captcha/sub?${t}`)
                        ])
                        .then((res) => {
                            debugger
                        })
                        .catch(err => {
                            debugger
                        })
                })
                .catch(err => {
                    debugger
                })
        })
        .catch((err) => {
            console.error(err)
        })

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凶凌 2022-09-18 16:58:01

后端的Access-Control-Allow-Origin看是否设置了指定的域名

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文