即使启用了CORS,也无法发出请求?

时间:2014-12-29 06:45:13

标签: angularjs laravel-4 cors same-origin-policy

我正在尝试从位于http://localhost:8000的AngularJS应用程序中调用http://localhost的Laravel中构建的API。我收到一个错误说:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/auth. This can be fixed by moving the resource to the same domain or enabling CORS.

我通过POSTMAN在http://localhost:8000发送了一个OPTIONS请求,这是响应:

Access-Control-Allow-Credentials → true
Access-Control-Allow-Headers → X-Requested-With, Content-Type, X-Auth-Token, Origin, Authorization
Access-Control-Allow-Methods → POST, GET, OPTIONS, PUT, DELETE
Access-Control-Allow-Origin → *, chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
Cache-Control → no-cache
Connection → close
Content-Type → text/html; charset=UTF-8
Date → Mon, 29 Dec 2014 06:33:26 GMT
Host → localhost:8000
Vary → Origin
X-Powered-By → PHP/5.5.9-1ubuntu4.5

从我所看到的,所有来源的所有方法都是允许的。我不明白为什么不能胜任这项工作。我错过了什么?

1 个答案:

答案 0 :(得分:0)

您还需要对$ httpProvider进行一些更改

http://better-inter.net/enabling-cors-in-angular-js/