简体   繁体   English

如果服务器http状态不是200,则启用CORS

[英]Enable CORS if the server http status is something other than 200

I enabled CORS on server side using: 我使用以下命令在服务器端启用了CORS:

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "GET, POST, OPTIONS"

I send a post message using angular $http.post() to server and everything is working good. 我使用angular $http.post()向服务器发送了一条消息,并且一切正常。 But if the server is sending 403 header, preflight fails. 但是,如果服务器正在发送403标头,则预检失败。

header("HTTP/1.1 403 Not allowed");

Whatever I send the same result occurs. 无论我发送什么结果,都会发生。 Even if I send http status 200. 即使我发送http状态200。

Cross-Origin Request Blocked: 
The Same Origin Policy disallows reading the remote resource at http://api.server.com/. 
(Reason: CORS preflight channel did not succeed).

For pre-flight to succeed, an OPTIONS call to the URL must return 200 along with the CORS headers. 为了使飞行前成功,对URL的OPTIONS调用必须返回200和CORS标头。

The follow up POST (or whatever) can return other status codes, but the OPTIONS request must succeed. 后续POST(或其他任何方式)可以返回其他状态代码,但是OPTIONS请求必须成功。

Header always add Access-Control-Allow-Origin "*"
Header always add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header always add Access-Control-Allow-Methods "GET, POST, OPTIONS"

Pay attention to the always . 注意always

For more information, see Apache doc 有关更多信息,请参阅Apache doc。

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

相关问题 CORS header 如果 http 状态代码不是 200,则缺少“Access-Control-Allow-Origin” - CORS header ‘Access-Control-Allow-Origin’ missing if http status code is not 200 CORS-状态200,但Chrome devtools控制台错误 - CORS - Status 200 but error in Chrome devtools console 当响应状态不是 200 时,为什么我无法将 .json() 方法应用于响应 object? - Why I'm not being able to apply the .json() method to a Response object when the Response status is other than 200? XmlHttpRequest状态= 0在远程服务器上,状态200在localhost - XmlHttpRequest status = 0 on remote server, status 200 on localhost AngularJs $ http post successCallback导致页面重定向,即使服务器以200状态响应 - AngularJs $http post successCallback is causing the page to redirect even when the server responds with a 200 status 收到状态为 200 且没有正文的 HTTP 请求 - HTTP request received with status 200 and without body HTTP响应状态为200,但无响应显示 - HTTP response status is 200, but no response shows 启用 CORS AngularJS 发送 HTTP POST 请求 - Enable CORS AngularJS to send HTTP POST request 无法接收CORS的http状态代码413 - Cannot receive the http status code 413 for CORS CORS 错误:它没有 HTTP 正常状态 - CORS Error: It does not have HTTP ok status
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM