簡體   English   中英

無法使用 header 向 api 發出獲取請求

[英]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 ). 因此,您的請求被阻止。 cors_issue

如果您控制此 API,請調整網絡服務器設置以設置適當的 header:例如

  • “訪問控制允許來源:https://YOUR_WEB_FRONTEND_DOMAIN.TLD”
  • (或者如果你只是想讓它在開發設置中工作)“Access-Control-Allow-Origin:*”

您也可以在此工具中測試 API https://www.test-cors.org/#?client_method=GET&client_credentials=false&server_url=%20https%3A%2F%2Ftest-docs.stores&server_enableFZ=true%2server_docs.stores&server_enableFZ =200&server_credentials=false&server_tabs=遠程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM