简体   繁体   English

Chrome没有'Access-Control-Allow-Origin'标题,但标题就在那里

[英]Chrome saying No 'Access-Control-Allow-Origin' header, but the header is there

This issue is mentioned in stackoverflow a dozen times already, but I have a different issue. stackoverflow中已经提到了这个问题十几次,但我有一个不同的问题。

Chrome first makes an "OPTIONS" call to get the headers. Chrome首先进行“OPTIONS”调用以获取标题。 As you can see, the correct headers are there. 如您所见,正确的标题就在那里。

在此输入图像描述

For some reason, Chrome doesn't notice the header and cancels the actual request in the same manner that it would if the header wasn't there at all. 出于某种原因,Chrome不会注意到标头并取消实际请求的方式与标头根本不存在时相同。

在此输入图像描述

The page actually makes three calls and curiously, one of them works. 该页实际上进行了三次调用并且好奇地,其中一个有效。

在此输入图像描述

So the question is, when the header really is there, why does Chrome not respect it? 所以问题是,当标题确实存在时,为什么Chrome不尊重它? What could I do to debug it? 我该怎么做才能调试它?

Update 更新

I tried adding Access-Control-Allow-Methods so now the header response from the OPTIONS call includes these response headers: 我尝试添加Access-Control-Allow-Methods所以现在OPTIONS调用的头响应包括这些响应头:

Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Methods:POST, GET, OPTIONS
Access-Control-Allow-Origin:*

The result is the same. 结果是一样的。

Setting the headers on the server side 在服务器端设置标头

I set the headers on the serverside on every request (in Global.asax.cs Application_BeginRequest) 我在每个请求上设置服务器端的头文件(在Global.asax.cs Application_BeginRequest中)

Response.Headers.Add("Access-Control-Allow-Origin", "*");
Response.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
Response.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");

After investigating with Fiddler 在与Fiddler调查之后

I looked through the raw request and response and found something surprising: The error is a simple HTTP 500 error from the application. 我查看了原始请求和响应,发现了一些令人惊讶的错误:错误是来自应用程序的简单HTTP 500错误。 Likely because the HTTP 500 error does not contain the right headers, Chrome doesn't show the returned error but instead shows the header related error. 可能因为HTTP 500错误不包含正确的标头,Chrome不会显示返回的错误,而是显示与标头相关的错误。

Answer 回答

So in conclusion, if Chrome gives says No 'Access-Control-Allow-Origin' header it might actually cover up a HTTP 500 error. 总而言之,如果Chrome提供了“ No 'Access-Control-Allow-Origin' header它实际上可能会掩盖HTTP 500错误。 This can be determined by checking request and response in Fiddler. 这可以通过检查Fiddler中的请求和响应来确定。

If Chrome says No 'Access-Control-Allow-Origin' header it might actually cover up a HTTP 500 error. 如果Chrome说No 'Access-Control-Allow-Origin' header它实际上可能会掩盖HTTP 500错误。 This can be determined by checking request and response in Fiddler. 这可以通过检查Fiddler中的请求和响应来确定。

暂无
暂无

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

相关问题 没有“ Access-Control-Allow-Origin”标头,但无权访问API - No 'Access-Control-Allow-Origin' header but no access to API 解决 Chrome 扩展程序的“不存在‘Access-Control-Allow-Origin’标头”问题 - Resolve "No 'Access-Control-Allow-Origin' header is present" issue with Chrome Extension 谷歌浏览器 - 请求的资源上没有Access-Control-Allow-Origin标头 - google chrome--No Access-Control-Allow-Origin header is present on the requested resource Chrome给出了“请求的资源错误中不存在'Access-Control-Allow-Origin'标头”,但firefox却没有 - Chrome gives “ No 'Access-Control-Allow-Origin' header is present on the requested resource error” but firefox doesn't AJAX请求中不存在“ access-control-allow-origin”标头 - No 'access-control-allow-origin' header is present in AJAX request (原因:CORS标头“ Access-Control-Allow-Origin”缺失) - (Reason: CORS header ‘Access-Control-Allow-Origin’ missing) 在源服务器上设置Access-Control-Allow-Origin标头 - Setting Access-Control-Allow-Origin header on source server 无法为No'Access-Control-Allow-Origin'标头加载XMLHttpRequest - XMLHttpRequest cannot load for No 'Access-Control-Allow-Origin' header 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 - No 'Access-Control-Allow-Origin' header is present on the requested resource. API端点的资源上没有Access-Control-Allow-Origin标头 - No Access-Control-Allow-Origin Header on resource of API endpoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM