【发布时间】:2024-05-02 14:55:02
【问题描述】:
我正在尝试从 http://localhost 的 AngularJS 应用程序调用在 http://localhost:8000 中内置的 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
据我所知,所有方法都允许来自所有来源。我不明白为什么这不起作用。我错过了什么?
【问题讨论】:
-
您使用哪个服务器和版本进行部署?
-
我想我正在使用用于测试的 PHP 服务器。我只是运行
php artisan serve并在http://localhost:8000上启动应用程序 -
不要尝试修复这个临时问题,而是从其余服务器提供静态页面,或者使用网络服务器将两个连接代理到一个主机
标签: angularjs laravel-4 cors same-origin-policy