小编Mar*_*ill的帖子

用于put/delete的CORS Cakephp 3.0预检失败

我正在尝试让CORS在我的应用程序中运行.但预检OPTIONS调用PUT和DELETE总是失败.例如PUT请求:

OPTIONS /api/events/5b165c71-0676-4d67-aceb-5546aff8ea03 HTTP/1.1
Host: rest.app
Connection: keep-alive
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: accept, content-type
Origin: http://frontend.app
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36
Accept: */*
Referer: http://frontend.app/events/5b165c71-0676-4d67-aceb-5546aff8ea03/edit
Accept-Encoding: gzip, deflate, sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,fr;q=0.2,it;q=0.2
Run Code Online (Sandbox Code Playgroud)

和我服务器的响应(CakePHP 3.0)

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:accept, content-type
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:http://frontend.app
Access-Control-Max-Age:86400
Connection:Keep-Alive
Content-Type:text/html; charset=UTF-8
Date:Tue, 26 May 2015 15:21:24 GMT
Keep-Alive:timeout=5, max=100
Server:Apache
Transfer-Encoding:chunked
X-DEBUGKIT-ID:75441af3-02b0-4945-a82c-5607287d4994
X-Powered-By:PHP/5.6.7
Run Code Online (Sandbox Code Playgroud)

错误消息是:

OPTIONS http://rest.app/api/events/5b165c71-0676-4d67-aceb-5546aff8ea03
XMLHttpRequest cannot load
http://rest.app/api/events/5b165c71-0676-4d67-aceb-5546aff8ea03.
    Invalid HTTP status code 404
Run Code Online (Sandbox Code Playgroud)

所以不允许实际的请求.我在Angular中将withCredentials标志设置为true.我还在尝试修复CORS问题或者是cakephp的错误吗?我试图用php和htaccess设置标题.除了GET和POST之外什么都没有用.

编辑: …

cors angularjs cakephp-3.0

7
推荐指数
1
解决办法
1796
查看次数

标签 统计

angularjs ×1

cakephp-3.0 ×1

cors ×1