您好,我想在获取POST请求后获取响应标头。我试图调试,看看里面有什么response
用console.log(response)
。我可以从中获取响应主体,responseData
但我不知道如何获取标头。我想同时获得标头和正文。请帮忙。谢谢:)
这是我所做的示例:
fetch(URL_REGISTER, {
method: 'POST',
body: formData
})
.then((response) => response.json())
.then((responseData) => {
if(responseData.success == 1){
this.setState({
message1: responseData.msg,
});
}
else{
this.setState({
message1: responseData.msg,
});
}
})
.done();
},
你可以这样
fetchData() {
var URL_REGISTER = 'https://www.example.com';
fetch(URL_REGISTER, {method: 'POST',body: formData})
.then(
function(response) {
console.log(response.headers.get('Content-Type'));
console.log(response.headers.get('Date'));
console.log(response.status);
console.log(response.statusText);
console.log(response.type);
console.log(response.url);
if (response.status !== 200) {
console.log('Status Code: ' + response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
});
}
)
.catch(function(err) {
console.log('Fetch Error', err);
});
}
阅读有关fetch的更多信息:fetch()简介
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句