小编ali*_*hie的帖子

从axios中的response.headers访问Set-Cookie值

我正在使用 VueJS 和 Axios 发送如下请求:

 axiosAPI.get('/login/flows', {params: {id: 'string'}})
            .then(res => {
                console.log('cookie', res.headers)
             }
Run Code Online (Sandbox Code Playgroud)

作为回报,服务器向我发送以下响应:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Type
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Length: 646
Content-Type: application/json; charset=utf-8
Date: Thu,xxxx 13:56:21 GMT
Set-Cookie: csrf_token=Lxv3zynm1Fua0hU0/W1+R2w=; Path=/.ory/kratos/public/; Domain=x.y ; Max-Age=31536000; HttpOnly; SameSite=Lax
Vary: Origin
Vary: Cookie
Run Code Online (Sandbox Code Playgroud)

如您所见,服务器在 Set-Cookies 中发送 csrf-token。但是当我尝试打印标题时,我无法获取并存储 csrf 令牌。此外,浏览器根本不会将令牌存储在存储部分中。

我需要在这个 cookie 中使用 csrf-token,但我不知道如何做到这一点?

注意:我无权访问后端代码。

http-headers vue.js axios

8
推荐指数
1
解决办法
4万
查看次数

如何使用 Axios 更改 'Sec-Fetch-Dest' 、 'Sec-Fetch-Mode' 、 'Sec-Fetch-Site' 和 'Sec-Fetch-User' 值?

我正在尝试通过 vue 中的 axios 实例发送请求,但我不知道如何为 'Sec-Fetch-Dest' 、 'Sec-Fetch-Mode' 、 'Sec-Fetch-Site' 和“Sec-Fetch-User”。

axios 文档中没有有关这些标头的信息,并且它们似乎不可编辑。

我尝试自定义和编辑默认的 config.headers 值(例如替换'cross-site''none'for 'Sec-Fetch-Site'header),但它不断发送默认值。

这是我在 vue 中的请求代码的示例:

axios.get('http://localhost:4433/some-endpoint/', {
                withCredentials: true, // if I set this to false nothing changes
                headers: {
                    'Sec-Fetch-Dest': 'document',
                    'Sec-Fetch-Mode': "navigate",
                    'Sec-Fetch-Site': 'none',
                    'Sec-Fetch-User': '?1'
                    }
                })
                .then(res => {console.log('response', res)})
                .catch(err => {console.log('error', err)})
Run Code Online (Sandbox Code Playgroud)

但发送请求的标头根本不会改变:

在此输入图像描述

提前致谢 !:)

javascript httprequest http-headers vue.js axios

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

axios ×2

http-headers ×2

vue.js ×2

httprequest ×1

javascript ×1