This error:
Access to fetch at 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest' from origin 'http://localhost:19006' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
...is returned by this fetch
request.
fetch(
"https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest",
{
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers":
"'Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token'",
"Content-Type": "application/json",
"X-CMC_PRO_API_KEY": API_KEY,
},
}
)
.then((response) => response.json())
.then((json) => console.log(json))
.catch((error) => console.error(error));
Why is this happening?
1- 向您的后端处理文件系统(php、cfm、aspx)等发送请求 2- 使用 curl 处理您的 api 并通过您的后端代码发送它,不要使用 javascript 来获取“https://pro-api.coinmarketcap” .com/v1/cryptocurrency/listings/latest”改为使用“http://yourdomain.com/yourendpoint” 3-现在在您的端点使用您的后端技术点击“https://pro-api.coinmarketcap.com/” v1/cryptocurrency/listings/latest" 通过 curl
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.