JW Player (api.jwplatform.com) - CORS 问题
JW Player (api.jwplatform.com) - CORS issues
我在使用 Angular2 开发的 Web 应用程序中使用 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
这些是请求 headers:
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 当然是我发送请求的域。
低于我从 end-point 获得的响应 headers:
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: *' header,因此不允许应用程序访问检索到的数据。
请注意,在浏览器控制台中,我可以看到 Status Code:200 OK 或 JSON data 来自服务器。
一切都在代理后面工作,但这只能在开发环境中工作。
谢谢你的帮助。
Should I assume that JWplayer don't properly manage CORS request on the 'api.jwplatform.com' end point?
是的。
所以如果你想让它正常工作,唯一可行的解决方案是设置反向代理或使用开放式反向代理,例如 https://cors-anywhere.herokuapp.com/
您的请求不是直接发送到 https://api.jwplatform.com/v1/channels/list/?…
,而是发送到 https://cors-anywhere.herokuapp.com/https://api.jwplatform.com/v1/channels/list/?…
,然后代理您的请求并使用 Access-Control-Allow-Origin
[=26] 响应浏览器=] 和其他预期的 CORS headers.
您可以在 Node.js 中使用 cors-anywhere package:
设置您自己的 CORS Anywhere 实例
npm install --save cors-anywhere
我在使用 Angular2 开发的 Web 应用程序中使用 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
这些是请求 headers:
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 当然是我发送请求的域。
低于我从 end-point 获得的响应 headers:
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: *' header,因此不允许应用程序访问检索到的数据。
请注意,在浏览器控制台中,我可以看到 Status Code:200 OK 或 JSON data 来自服务器。 一切都在代理后面工作,但这只能在开发环境中工作。
谢谢你的帮助。
Should I assume that JWplayer don't properly manage CORS request on the 'api.jwplatform.com' end point?
是的。
所以如果你想让它正常工作,唯一可行的解决方案是设置反向代理或使用开放式反向代理,例如 https://cors-anywhere.herokuapp.com/
您的请求不是直接发送到 https://api.jwplatform.com/v1/channels/list/?…
,而是发送到 https://cors-anywhere.herokuapp.com/https://api.jwplatform.com/v1/channels/list/?…
,然后代理您的请求并使用 Access-Control-Allow-Origin
[=26] 响应浏览器=] 和其他预期的 CORS headers.
您可以在 Node.js 中使用 cors-anywhere package:
设置您自己的 CORS Anywhere 实例npm install --save cors-anywhere