[英]Content-type from fetch in locally run React code
I am new to front end dev.我是前端开发的新手。 How can I set "application/json" content-type and gzip content-encoding in the fetch call 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
}
});
You could try this你可以试试这个
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'
}
});
but I'm not sure what do you want with "gzip content-encoding".但我不确定“gzip 内容编码”你想要什么。 If the console prints any errors, they can be helpful too如果控制台打印任何错误,它们也会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.