这是一个由两部分组成的问题。
首先: 我们在嵌入 soundcloud 资源时遇到问题,我们的网站使用 https。 加载嵌入式资源时,它会发出请求(例如 url:http://soundcloud.com/oembed?format=js&url=https://soundcloud.com/user908553597%2Fann-marie-in-my-feelings-treat-me-like-somebody-remake&iframe=true),它会正确响应:
({
"version":1.0,
"type":"rich",
"provider_name":"SoundCloud",
"provider_url":"http://soundcloud.com",
"height":400,"width":"100%",
"title":"Ann Marie - In My Feelings (Treat Me Like Somebody Remake) by user908553597",
"description":"",
"thumbnail_url":"http://i1.sndcdn.com/artworks-000146535766-ycam16-t500x500.jpg",
"html":"\u003Ciframe width=\"100%\" height=\"400\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?visual=true\u0026url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F246270367\u0026show_artwork=true\"\u003E\u003C/iframe\u003E",
"author_name":"user908553597",
"author_url":"http://soundcloud.com/user908553597"
});
但是,“provider_url”和“thumbnail_url”是通过 http 协议(protocol)返回的,因为我们的网站是通过 https 运行的,这会导致问题。 是否可以使用标志或参数来确保响应中的所有资源都使用 https,或者这是否需要更改您的 API?
第二: 某些资源似乎会返回 http 403 响应代码,例如:http://soundcloud.com/oembed?format=js&url=https://soundcloud.com/richgurl_1%2Ftink-treat-me-like-somebody&iframe=true这是 API 处理某些资源请求的方式吗? IE。这是一种可预测的行为吗,以便可以对返回的 403 采取行动。
提前致谢
最佳答案
所以我想通了, 或者至少是一个易于管理的解决方案。更改协议(protocol)就可以了 示例网址:https://soundcloud.com/oembed?format=js&url=https://soundcloud.com/user908553597%2Fann-marie-in-my-feelings-treat-me-like-somebody-remake&iframe=true
thumbnail_url 通过 http 返回,我的解决方案是通过 Angular 中的 .ts 文件将协议(protocol)更改为 https,该文件使用替换对上述 url 进行响应。然后使用 thumbnail_url 的 iframe 有一个带有所需协议(protocol)的 url。
关于javascript - 通过 https 嵌入的 Soundcloud 和一些资源响应 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44154392/