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

ali*_*hie 7 javascript httprequest http-headers vue.js axios

我正在尝试通过 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)

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

在此输入图像描述

提前致谢 !:)

Pie*_*our 7

不幸的是,这些是安全标头,它们不能被 JS 覆盖。

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Dest