微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过CORS策略阻止从来源“ http:// localhost:3000”访问“ https://www.cloudflare.com/cdn-cgi/trace”

如何解决通过CORS策略阻止从来源“ http:// localhost:3000”访问“ https://www.cloudflare.com/cdn-cgi/trace”

我该如何解决

let response = await fetch("https://www.cloudflare.com/cdn-cgi/trace",{
    // credentials: 'include',method: 'GET',// method: 'POST',headers: {'Content-Type': 'application/json'}
})

可以从以下网址访问“ https://www.cloudflare.com/cdn-cgi/trace” 来源'http:// localhost:3000'已被CORS策略阻止: 请求标头字段的内容类型不允许 飞行前响应中的Access-Control-Allow-Header。

解决方法

您可以尝试这样做:

async function test () {
  let response = await fetch("https://www.cloudflare.com/cdn-cgi/trace",{mode: "cors"});
  let text = await response.text();
  console.log(text)
}
test()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。