jsonp跨域被CORB拦截,有何解决方法?

* 最近在用vue仿写QQ音乐的web移动端,使用jsonp请求数据。在请求排行榜数据的时候Chrome报CORB拦截问题,具体的URL为

https://c.y.qq.com/v8/fcg-bin/fcg_myqq_toplist.fcg?g_tk=5381&uin=704838764&format=json&inCharset=utf-8&outCharset=utf-8&notice=0&platform=h5&needNewCode=1&jsonpCallback=__jp0

* 已知URL没有问题,在浏览器地址输入可以获取得到数据

在开发者工具查看了Response Header的Content-type为application/x-javascript,不知道会不会与这个有关呢

clipboard.png

求教各位大佬有没有什么解决方案o(╥﹏╥)o

阅读 28.3k
4 个回答

将链接写到script标签src 用safari 打开,会发现请求是返回了json格式数据,数据格式不是jsonp形式(callback(data))图片描述

图片描述

json格式数据,在chrome 里面触发了Cross-Origin Read Blocking (CORB)链接描述 所以显示为
图片描述

所以原因在于:请求返回数据的格式不对(或者请求的参数不对)
上文的链接:修改参数format=jsonp 即如下
https://c.y.qq.com/v8/fcg-bin...
使用这个链接会看到callback也用错了,再修改jsonpCallback = MusicJsonCallback 数据就正常返回了(通常是Callback等于__jp0,服务器端就会返回__jp0(data)形式,此处却不是,毕竟是别人的接口)。
(Cross-Origin Read Blocking,走过路过了解一下~~ 哈哈)

是浏览器的安全策略禁止了这个,防止跨域攻击啥的 参考 https://www.chromium.org/Home...

Cross-Origin Read Blocking (CORB) is a new web platform security feature that helps mitigate the threat of side-channel attacks (including Spectre). It is designed to prevent the browser from delivering certain cross-origin network responses to a web page, when they might contain sensitive information and are not needed for existing web features. For example, it will block a cross-origin text/html response requested from a <script> or <img> tag, replacing it with an empty response instead. This is an important part of the protections included with Site Isolation.

clipboard.png

这里qq音乐已经指定了只有人家qq的域名才可以用这个js。就是防止你直接盗用。

你直接把代码手动下载下来, 然后地址指向本地不就好了吗

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题