[英]Content-type from fetch in locally run React code
我是前端開發的新手。 如何在本地運行的 React 代碼中的 fetch 調用中設置“application/json”內容類型和 gzip 內容編碼?
const data = await fetch(url, {
method: 'post',
body: body,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json' // this does not work when run locally
}
});
你可以試試這個
const data = await fetch(url, {
method: 'post',
body: JSON.stringify(body), // this will encode body to string, assuming it's an Object
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
但我不確定“gzip 內容編碼”你想要什么。 如果控制台打印任何錯誤,它們也會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.