【发布时间】:2019-01-03 03:17:03
【问题描述】:
如果我使用 Axios 或 Fetch 向此公共端点发出 ajax 请求:
http://api.flickr.com/services/feeds/photos_public.gne?format=json
我收到以下错误:
Access to fetch at 'http://api.flickr.com/services/feeds/photos_public.gne?format=json' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
但是,如果我使用 Postman 发出相同的请求,我可以看到结果很好。如何解决这个问题?
【问题讨论】:
-
CORS 是默认情况下在浏览器上强制执行的一项功能 - 可以禁用,但不应禁用。 Postman 不是浏览器,没有这样的限制。
标签: javascript ajax api fetch axios