[英]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.