【发布时间】:2017-07-01 17:51:16
【问题描述】:
我在使用 Angular2 开发的网络应用程序中使用 JW 平台服务时遇到问题。
我是否应该假设 JWplayer 没有正确管理 'api.jwplatform.com' 端点上的 CORS 请求?
情况就是这样。我正在发送以下请求
Request URL:https://api.jwplatform.com/v1/channels/list/?api_format=xml&api_key=BNgTpOY5&api_nonce=33502681&api_timestamp=1487003685&types_filter=manual&api_signature=287df9d7dcefaf9bcae656c518a4cc29718bcaeb
Request Method:GET
Status Code:200 OK
Remote Address:10.68.96.40:8080
这些是请求标头:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,fr;q=0.2,de;q=0.2,es;q=0.2
Connection:keep-alive
Host:api.jwplatform.com
Origin:https://mydomain
Referer:https://mydomain/channels
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
were mydomain 当然是我发送请求的域。
在我从端点获得的响应标头下方:
Cache-Control:no-cache
Connection:keep-alive
Content-Length:3847
Content-Type:application/xml; charset=utf-8
Date:Mon, 13 Feb 2017 16:34:46 GMT
Pragma:no-cache
Server:openresty
X-RateLimit-Limit:60
X-RateLimit-Remaining:58
X-RateLimit-Reset:1487003700
如上所示,响应中没有 'Access-Control-Allow-Origin: *' 标头,因此不允许应用访问检索到的数据。
请注意,在浏览器控制台中,我可以同时看到 Status Code:200 OK 或来自服务器的 JSON 数据。 一切都在代理后面工作,但这只能在开发环境中工作。
谢谢你帮助我。
【问题讨论】:
-
CORS 是一个服务器设置。 Angular 对此概不负责。见enable-cors.org/server.html