[英]How do I resolve this CORS error on Spotify Search API?
我对 Javascript 中的 API 比较陌生。 我正在尝试使用以下代码连接到 Spotify 的 API。 我已经有了获得有效令牌的代码。
function searchApi() {
const searchBox = window.document.getElementById("searchBox");
const searchString = searchBox.value;
fetch(searchUrl, {
q: searchString,
type: "artist",
headers: {
'Bearer': token
}
}).then(function (response){
return response.json();
}).then(function (data){
console.log(data);
})
}
但是,我目前收到 CORS 错误,我不确定如何解决。
Access to fetch at 'https://api.spotify.com/v1/search' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field bearer is not allowed by Access-Control-Allow-Headers in preflight response.
有谁知道我应该怎么做才能解决这个错误?
您收到此信息是因为您发送的获取请求来自 http 站点而不是 https 站点,即它不使用 ssl。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.