我正在尝试对 rotten tomatoes API 执行一个简单的 http GET 请求在我的 AngularJS 应用程序中,但是当我运行它时,我在浏览器控制台中得到了这个:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://api.rottentomatoes.com/api/public/v1.0/movies/770672122.json?apikey=[myApiKey]. This can be fixed by moving the resource to the same domain or enabling CORS.
注意:“[myApiKey]”已替换为我的实际 key ...
我已经在 Chrome 和 Firefox 上尝试过这个,虽然我知道在启动 Chrome 时可以附加一些参数来禁用它,但普通用户不知道如何做到这一点,所以从浏览器兼容性来看选项对我不起作用。我还尝试从我的桌面以及本地 Tomcat 实例运行我的应用程序。
所以我看到这可以通过启用 CORS 来解决。现在我该怎么做?显然我不能接触烂番茄服务器,所以这必须从我这边——客户端来完成。
最佳答案
您需要enable CORS on the server-side code by setting the Access-Control-Allow-Origin HTTP或通过 changing the web.config .
关于javascript - 跨源请求被阻止——这可以通过启用 CORS 来解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24776062/