【发布时间】:2020-09-11 22:16:46
【问题描述】:
我有一个 React 应用程序以这种方式从服务器获取数据:
fetch('http://localhost:5000/records',{
method:'GET',
headers:{
'ACCEPT':'application/json',
'Content-Type':'application/json'
}
})
.then(response => response.json())
.then(data => {
this.setState({
records: data,
});
});
}
检查网络活动(开发工具 Chrome/Firefox),我看到了:
我可以将“Accept-Encoding”添加到我的请求标头并为其赋予任何值,或者我可以将其从标头中完全删除。无论我做什么,检查网络活动总是显示我的请求标头接受 gzip、deflate 和 br。这是正常的吗?有没有办法让 fetch 告诉服务器它不需要任何响应编码?
我尝试按照here 的描述为 gzip 赋予 0 的 qvalue,但我仍然在网络选项卡中看到相同的结果。
headers:{
'ACCEPT':'application/json',
'Content-Type':'application/json',
'Accept-Encoding': 'gzip; q=0'
}
【问题讨论】:
标签: javascript reactjs react-native fetch