通过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()