gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:20:40 24 4
gpt4 key购买 nike

我使用以下方法在服务器端启用了 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"

我使用 Angular $http.post() 向服务器发送一条帖子消息,一切正常。但如果服务器发送 403 header ,预检就会失败。

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

无论我发送什么,都会出现相同的结果。即使我发送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).

最佳答案

为了成功预检,对 URL 的 OPTIONS 调用必须返回 200 以及 CORS header 。

后续的 POST(或其他)可以返回其他状态代码,但 OPTIONS 请求必须成功。

关于javascript - 如果服务器 http 状态不是 200,则启用 CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36234016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com