无法向 POST 请求添加请求标头

问题描述 投票:0回答:1

我通过使用负载和标头来访问 API,在请求标头中,我看到

Content-Type : 'application/json'
仍然在浏览器中
Content-Type : 'text/plain'

因为在后端我得到了有效负载

Content-Type : 'text/plain'

export const abctrigger = (payload , signal) => {
  Return fetch (API_URL, {
    method: post,
    Signal: signal
    Body: JSON.stringify(payload),
    headers: {
      Content-Type : 'application/json'
    }
  })
    .then((response) => response.text())
    .then((response) => {
      return respon se;
    })
}
 

我想将请求标头更改为

Content-Type : 'application/json'

javascript reactjs api
1个回答
0
投票

试试这个:

headers: {
  "Content-Type": 'application/json'
}

而不是这个:

headers: {
  Content-Type : 'application/json'
}

并检查您的 IDE 设置,因为使用 ms-code 后会出现错误:

Parsing error: Unexpected token, expected ","
© www.soinside.com 2019 - 2024. All rights reserved.