gpt4 book ai didi

ember.js - CORS飞行前 channel 未成功

转载 作者:行者123 更新时间:2023-12-04 04:04:44 25 4
gpt4 key购买 nike

我正在尝试使用PHP REST框架作为本地api构建Ember应用程序。 Ember应用程序通过http://localhost:4200提供,而api仅通过http://localhost提供。这导致CORS问题。我已经尝试了所有可以想到的方法,但仍然收到错误消息,说请求已被阻止,并且预检 channel 未成功。在Firefox或Chrome浏览器中无法成功执行。

我已将以下内容添加到api的.htaccess文件中:

Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Origin "http://localhost:4200"
Header set Access-Control-Allow-Credentials true
Header set Access-Control-Allow-Headers "accept, content-type"

这是我的请求 header :
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://localhost:4200
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

和响应头:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: accept, content-type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: http://localhost:4200
Connection: close
Content-Type: text/html; charset=utf-8
Date: Fri, 24 Jul 2015 17:10:49 GMT
Server: Apache/2.4.9 (Win64) PHP/5.5.12
Set-Cookie: 24fd751c8630b64fcf935a94e8bcef46=qih6pfnqo94d4cgi5b5d79h4i6; path=/
Transfer-Encoding: chunked
X-Powered-By: PHP/5.5.12
p3p: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"

有什么想法或解决方案吗?任何帮助表示赞赏。谢谢!

最佳答案

您的飞行前OPTIONS请求是否返回200?您可以尝试使用.htaccess返回200响应,如下所示:

Header always set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header always set Access-Control-Allow-Origin "http://localhost:4200"
Header always set Access-Control-Allow-Credentials true
Header always set Access-Control-Allow-Headers "accept, content-type"

RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

关于ember.js - CORS飞行前 channel 未成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31617946/

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