ssl - 如何解决 SSL 错误获取音频路径
问题描述
我一直在尝试在 HTML 音频元素中使用来自歌词 API 的 mp3 文件 - https://lyrics.ovh 。但是我一直收到以下 cors 错误(它不会在本地发生,但是当我部署到 gitpages 时会发生)。
加载资源失败:net::ERR_CERT_COMMON_NAME_INVALID
这就是我一直试图解决的方法:
我已经尝试过这里提到的解决方案之一:请求的资源上没有“Access-Control-Allow-Origin”标头——当尝试从 REST API 获取数据时,将我自己的代理部署到 Heroku。它适用于我需要的一个 url,但对于包含 mp3 路径的那个却没有。响应返回状态:200,但我收到错误:JSON 中的意外令牌。
控制台错误:
GET http://127.0.0.1:5500/[object%20Promise] 404 (Not Found) script.js:89 Uncaught (in promise) SyntaxError: Unexpected token I in JSON at position 0
const cors = https://my-proxy.herokuapp.com
// get Mp3
async function getMP3(url) {
const res = await fetch(`${cors}/${url}`, {
headers: {
"Content-Type": "audio/mpeg",
Accept: "audio/mpeg",
},
});
const data = await res.json(); // this line causes the error
}
// url 示例:(代理 url + mp3 路径)
https://my-proxy.herokuapp.com/http://cdn-preview-e.deezer.com/stream/c-e6b5f2295c3af5280cc00b3bf842ff57-9.mp3
// 音频元素
<audio controls>
<source src="${getMP3(url)}" type="audio/mpeg">
</audio>
解决方案
ERR_CERT_COMMON_NAME_INVALID
is an HTTPS error, not a CORS error. It means that the SSL certificate of the domain you're attempting to connect to is invalid.
More specifically, ERR_CERT_COMMON_NAME_INVALID
means it's invalid because the SSL certificate is registered to a different domain(Or subdomain) than the domain you're attempting to connect to.
推荐阅读
- google-cloud-platform - 无法发送邀请,因为该帐号已停用 Google Cloud Platform
- javascript - 从图像数组中弹出打开图像
- sql - 在 SQL 查询中省略错误数据
- javascript - 如何在 DevTools 中“观看”密码并确认密码字段?- AngularJS 表单
- postgresql - Postgres/PostGIS st_distance_sphere 函数与 EntityManager.createQuery 无法理解的错误
- javascript - 如何使用fabric js在下部画布背景图像上绘制多边形?
- javascript - ReactNative 调试模式下的 XMLHttpRequest 错误
- python - 未找到模块 matplotlib.finance
- cassandra - Cassandra 数据在没有设置 TTL 的情况下压缩直到删除?
- php - 我想在 Magento 2 中创建一个类别价格规则,但该规则未正确应用于特价产品