简体   繁体   English

使用正确的标头和OPTIONS请求,仍会获得“所请求的资源上不存在Access-Control-Allow-Origin标头”

[英]With correct headers and OPTIONS request, still getting “No Access-Control-Allow-Origin header is present on the requested resource”

So I'm trying to make a cross-domain AJAX request with javascript. 因此,我正在尝试使用javascript进行跨域AJAX请求。

My OPTIONS request is executing without any problems, and I'm getting back Access-Control-Allow-Origin:* as a response header. 我的OPTIONS请求正在执行,没有任何问题,我将Access-Control-Allow-Origin:*作为响应标头取回来。 However, when trying to make the subsequent POST request, I get the following error: 但是,当尝试发出后续的POST请求时,出现以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://phoenix-client.local' is therefore not allowed access.

I've verified multiple times that my OPTIONS request is indeed sending the correct response, including the Access-Control-Allow-Origin header, but the browser seems to ignore it :( 我已经多次验证我的OPTIONS请求确实发送了正确的响应,包括Access-Control-Allow-Origin标头,但浏览器似乎忽略了它:(

Any ideas? 有任何想法吗?

edit - A couple things I've been noticing: 编辑-我注意到的几件事:

If I try to update the headers my server is sending, everyone else except me gets the newly updated headers when they make a request. 如果我尝试更新服务器正在发送的标头,则除我以外的其他所有人在发出请求时都会获得新近更新的标头。 It's as if my computer is caching the responses to OPTIONS requests. 好像我的计算机正在缓存对OPTIONS请求的响应。

This is only occurring for one of my AJAX requests. 这仅发生在我的AJAX请求之一中。 I make multiple requests before the request that fails, and all of them work fine (with the headers as is) except for the last one. 我在失败的请求之前发出了多个请求,除最后一个请求外,所有其他请求均正常工作(标头保持原样)。

EDIT!!!! 编辑!!!!

Updating this post (extremely late). 更新此帖子(极其晚)。 This ended up not being a CORS error. 最终这不是CORS错误。 I get a false "Access-Control-Allow-Origin" error from Chrome, but when I run the AJAX request directly, I get the real error (which typically is supposed to be an error 500, with some sort of PHP error messaging). 我从Chrome收到一个错误的“ Access-Control-Allow-Origin”错误,但是当我直接运行AJAX请求时,我得到了真正的错误(通常应该是错误500,带有某种PHP错误消息) 。 Still unsure why this is occurring though... 仍然不确定为什么会这样...

In case others run into this issue, I'll combine some of my comments above. 如果其他人遇到此问题,我将结合上面的一些评论。

The spec outlines very specific behavior for network errors in the context of CORS requests. 该规范概述了在CORS请求的上下文中针对网络错误的非常具体的行为。 For preflighted requests, a network error or non 2xx response will be reported as a CORS error, even if the ACAO header is correct. 对于预检请求,即使ACAO标头正确,也会将网络错误或非2xx响应报告为CORS错误。 For the underlying request, the specific error should be visible though, per my understanding of the spec. 根据我对规范的理解,对于基础请求,具体错误应该是可见的。 That said, Chrome appears to be displaying a CORS error on the underlying request with a non 2xx. 也就是说,Chrome似乎在非2xx的基础请求上显示CORS错误。 Looks like this is a reported bug in Chrome: http://code.google.com/p/chromium/issues/detail?id=269192 . 看起来这是Chrome中的一个已报告的错误: http : //code.google.com/p/chromium/issues/detail ?id= 269192

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 启用了 Elasticsearch https cors,但仍然在请求的资源上不存在“Access-Control-Allow-Origin”标头 - Elasticsearch https cors enabled but still getting No 'Access-Control-Allow-Origin' header is present on the requested resource 获取请求不会通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头 - Getting request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource Javascript-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource 角度4-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Angular 4 - No 'Access-Control-Allow-Origin' header is present on the requested resource NodeJ在所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - NodeJs No 'Access-Control-Allow-Origin' header is present on the requested resource Access-Control-Allow-Origin header 存在于请求的资源上 - Access-Control-Allow-Origin header is present on the requested resource 请求的资源 .htaccess 上不存在 Access-Control-Allow-Origin 标头 - No Access-Control-Allow-Origin header is present on the requested resource .htaccess XMLHttpRequest请求的资源上没有“Access-Control-Allow-Origin”标头 - XMLHttpRequest No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在Access-Control-Allow-Origin标头 - Access-Control-Allow-Origin header is not present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM