【问题标题】:JW Player (api.jwplatform.com) - CORS issuesJW Player (api.jwplatform.com) - CORS 问题
【发布时间】: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 jwplayer7


【解决方案1】:

我是否应该假设 JWplayer 没有正确管理 'api.jwplatform.com' 端点上的 CORS 请求?

是的。

因此,如果您想使其正常工作,唯一可行的解​​决方案是设置反向代理或使用开放的反向代理,例如 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 标头和其他预期的CORS 标头响应浏览器。

您可以使用 cors-anywhere package 在 Node.js 中设置自己的 CORS Anywhere 实例:

npm install --save cors-anywhere

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2019-05-16
    • 2019-12-05
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 2011-08-21
    相关资源
    最近更新 更多