gpt4 book ai didi

javascript - 为什么在调用另一个域时设置 X-Requested-With header 时浏览器不会抛出错误?

转载 作者:行者123 更新时间:2023-12-02 21:02:46 26 4
gpt4 key购买 nike

我正在 localhost 上运行我的服务器。我尝试使用 fetch 发送 http 请求,并将 cors 模式设置为 no-cors。我将请求发送到 google.com 域中的随机资源。此请求将 X-Requested-With header 设置为某个自定义值,保存“Foo”。此请求成功通过并在浏览器上返回 404 NOT FOUND http 状态代码。

但我期望请求根本不应该发送,并且浏览器应该抛出错误,因为以下 header 允许设置跨域

Accept
Accept-Language
Content-Language
Last-Event-ID
Content-Type

我的期望是错误的吗?

最佳答案

来自the specification :

Otherwise, if the context object’s guard is "request-no-cors" and name/value is not a no-CORS-safelisted request-header, return.

尝试设置 X-Requested-With 会失败,并且会不带 header 发出请求。

关于javascript - 为什么在调用另一个域时设置 X-Requested-With header 时浏览器不会抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61303207/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com