gpt4 book ai didi

cors - 为什么 CORS 请求在 Microsoft Edge 中失败,但在其他浏览器中有效?

转载 作者:行者123 更新时间:2023-12-03 23:54:49 24 4
gpt4 key购买 nike

我正在使用 jQuery 发送跨源 ajax 请求,它们在 IE11、Chrome 和 Firefox 中运行良好,但它们在 Edge 中失败并出现以下错误:

SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access isdenied.


有趣的是,我使用 Fiddler 试图弄清楚发生了什么以及 Fiddler 何时运行并捕获请求一切正常。一旦我关闭 Fiddler 或暂停捕获,它就会再次失败。
该站点在我的本地机器 (webpack-dev-server) 上运行,通过本地网络向 WebAPI 服务发出请求。
我的主机文件是这样设置的:
127.0.0.1   local.myapp.test
192.168.0.111 api.myapp.test
这在生产中应该不是问题,因为站点和 API 将托管在同一个地方,但它对于开发和测试来说是无价的。

更新:
感谢 Eric Law on the Telerik forums我现在知道为什么在启用 Fiddler 时它的行为会有所不同 - Edge 正在切换到本地 Intranet 区域,因为 Fiddler 进行了代理设置更改,并且 Intranet 区域的安全级别较低。

There are a few possibilities; without exact details of your configuration, we're just shooting in the dark.

One possibility is that your computer is configured with an Intranet zone and that Intranet zone is dependent on a proxy configuration script: http://blogs.msdn.com/b/ieinternals/archive/2012/06/05/the-local-intranet-security-zone.aspx. When Fiddler is running, the proxy settings are pointed at Fiddler itself.


我要将本地 Intranet 区域安全级别提高到中高以匹配 Internet 区域,然后使用 Fiddler 尝试找出 Edge 对 CORS 请求感到不安的原因。

最佳答案

我将在下面逐字逐字列出 Eric Lawrence(Fiddler 的创建者)在 Fiddler 论坛上提供的答案:

One possibility is that your computer is configured with an Intranet zone and that Intranet zone is dependent on a proxy configuration script: http://blogs.msdn.com/b/ieinternals/archive/2012/06/05/the-local-intranet-security-zone.aspx. When Fiddler is running, the proxy settings are pointed at Fiddler itself.

... there's another factor at work here if you're using an Intranet site as the target of an XHR from a site in the Internet zone.

Edge runs in Enhanced Protected Mode (AppContainer). That has a feature which blocks access to Private Network Resources from Internet-Zone processes. See the "Private Network resources" section of http://blogs.msdn.com/b/ieinternals/archive/2012/03/23/understanding-ie10-enhanced-protected-mode-network-security-addons-cookies-metro-desktop.aspx for more details.


我将 local.myapp.test(我从中运行 SPA 的 URL)添加到 Internet 选项中的本地 Intranet 区域,现在 Edge 很高兴无需 Fiddler。

关于cors - 为什么 CORS 请求在 Microsoft Edge 中失败,但在其他浏览器中有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35176082/

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