[英]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.