【問題】js fetch和 cors policy ---header Access-Control-Allow-Origin 問題
追蹤話題
【問題】js fetch和 cors policy ---header Access-Control-Allow-Origin 問題
網頁開發
Loordb (yuchinchen)
2021-10-05 15:42:07
#1
const getRawData = (URL) => {
return fetch(URL, {
method: "GET",
mode: 'cors',
headers:{'Access-Control-Allow-Origin':'*'},
})
.then((response) => response.text())
.then((data) => {
return data;
});
};
瀏覽器上:
from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
但是我Access-Control-Allow-Origin已經加入header了 請問有人看出是哪裡出問題了嗎(是Local server 所以排除security issue)
看較舊的 3 則留言
~跡~:
B4
2021-10-05 19:46
你有電腦開http服務的話,用自己的伺服器去抓對方伺服器的資料,js只跟自己的伺服器拿資料。
~跡~:
B5
2021-10-05 19:46
就是用自己的後端代理抓資料的意思
Loordb:
B6
2021-10-05 21:29
那如果我是要對外部網頁?
~跡~:
B7
2021-10-05 22:02
用你的後端去連外面的網頁