iT邦幫忙

0

Postman 上發送API是成功的.但是運用Postman所產生的JS fetch程式碼確不成功,能否幫忙解惑哪裡錯了

  • 分享至 

  • xImage

const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

const raw = JSON.stringify({
"store_code": "3045",
"f1": [
{
"pc": "102",
"pn": "A1",
"pp": "1.0",
"f1": "Z001",
"f2": "製作中"
}
],
"is_base64": "0",
"sign": "80805d794841f1b4"
});

const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};

fetch("http://47.106.233.11/api/default/product/create_multiple", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

2
janlin002
iT邦好手 1 級 ‧ 2024-04-01 21:22:13
最佳解答

不成功的原因是什麼?有錯訓?還是根本沒執行?

但我猜應該是 CORS

0
davidchen0117
iT邦新手 4 級 ‧ 2024-04-02 14:54:14

把myHeaders 移除試試看呢?

const raw = JSON.stringify({
"store_code": "3045",
"f1": [
{
"pc": "102",
"pn": "A1",
"pp": "1.0",
"f1": "Z001",
"f2": "製作中"
}
],
"is_base64": "0",
"sign": "80805d794841f1b4"
});

const requestOptions = {
method: "POST",
body: raw,
redirect: "follow"
};

fetch("http://47.106.233.11/api/default/product/create_multiple", requestOptions)
.then(response => response.json()) // 改為解析為JSON
.then(result => console.log(result))
.catch(error => console.error(error));

我要發表回答

立即登入回答