最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change 'Sec-Fetch-Dest' , 'Sec-Fetch-Mode' , 'Sec-Fetch-Site&#39

programmeradmin1浏览0评论

I am trying to send a request through an axios instance in vue and I do not know how can I set a certain value for 'Sec-Fetch-Dest' , 'Sec-Fetch-Mode' , 'Sec-Fetch-Site' and 'Sec-Fetch-User'.

There is no information in axios documentation about these headers and it seems they are not editable.

I tried to customize and edit default config.headers values (for example replace 'cross-site' with 'none' for 'Sec-Fetch-Site' header) but it keeps sending the default values.

Here is an example of my request code in 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)})

but sending request's headers will not change at all:

Thanks in advance ! :)

I am trying to send a request through an axios instance in vue and I do not know how can I set a certain value for 'Sec-Fetch-Dest' , 'Sec-Fetch-Mode' , 'Sec-Fetch-Site' and 'Sec-Fetch-User'.

There is no information in axios documentation about these headers and it seems they are not editable.

I tried to customize and edit default config.headers values (for example replace 'cross-site' with 'none' for 'Sec-Fetch-Site' header) but it keeps sending the default values.

Here is an example of my request code in 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)})

but sending request's headers will not change at all:

Thanks in advance ! :)

Share Improve this question edited Feb 27, 2022 at 9:12 ali forooghie asked Feb 26, 2022 at 13:26 ali forooghieali forooghie 1832 gold badges2 silver badges8 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 9

Unfortunately, these are secure headers, they can't be overridden by JS.

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

I know one way to change Sec-Fetch-Mode. Try the method below

'Sec-Fetch-Mode': "navigate",

->

fetch(..., {
mode: 'no-cors',
})

result => Sec-Fetch-Mode: no-cors

For anybody that thought that 'fetch' can magically solve their issue, IT CAN NOT.

Even though you will be able to execute the request and will be able to clearly see the response in your browsers developer console, you won't be able to access it through the normal fetch methods like blob() or text() for example.

You can find a more detailed explanation here

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论