Firefox #39;Cross-Origin Request Blocked#39; despite headers(尽管有标头,Firefox 跨源请求被阻止)
问题描述
我正在尝试发出一个简单的跨域请求,而 Firefox 一直以这个错误阻止它:
I'm trying to make a simple cross-origin request, and Firefox is consistently blocking it with this error:
跨域请求被阻止:同源策略不允许读取 [url] 处的远程资源.这可以通过将资源移动到同一域或启用 CORS 来解决.[网址]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [url]. This can be fixed by moving the resource to the same domain or enabling CORS. [url]
它在 Chrome 和 Safari 中运行良好.
It works fine in Chrome and Safari.
据我所知,我已经在我的 PHP 上设置了所有正确的标头以允许它工作.这是我的服务器响应的内容
As far as I can tell I've set all the correct headers on my PHP to allow this to work. Here's what my server is responding with
HTTP/1.1 200 OK
Date: Mon, 23 Jun 2014 17:15:20 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.4-14+deb7u8
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type
Access-Control-Request-Headers: X-Requested-With, accept, content-type
Vary: Accept-Encoding
Content-Length: 186
Content-Type: text/html
我尝试过使用 Angular、jQuery 和一个基本的 XMLHTTPRequest 对象,如下所示:
I've tried using Angular, jQuery, and a basic XMLHTTPRequest object, like so:
var data = "id=1234"
var request = new XMLHttpRequest({mozSystem: true})
request.onload = onSuccess;
request.open('GET', 'https://myurl.com' + '?' + data, true)
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
request.send()
...它适用于除 Firefox 之外的所有浏览器.有人可以帮忙吗?
...and it works in every browser except Firefox. Can anyone help with this?
推荐答案
原来这与 CORS 无关——这是安全证书的问题.误导性错误 = 4 小时的头痛.
Turns out this has nothing to do with CORS- it was a problem with the security certificate. Misleading errors = 4 hours of headaches.
这篇关于尽管有标头,Firefox '跨源请求被阻止'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:尽管有标头,Firefox '跨源请求被阻止'
基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01