[英]Can't make a get request with header to an api
我正在尝试向 api 发出获取请求,但出现错误:无法获取,这里可能有什么问题?
const getData = () => { fetch("https://test-docs.stores.kg/api/categories", { method: "GET", headers: { secretKey: "test_key", accept: "application/json " } }).then((res) => res.json()).then((res) => console.log(res)); }; getData();
Seems like the API you're querying is not setting a CORS header (check for reference https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS ). 因此,您的请求被阻止。
如果您控制此 API,请调整网络服务器设置以设置适当的 header:例如
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.