我将我的RN应用从0.58.3版本更新为0.59.4,而不是bodyText服务器现在返回bodyBlob
我尝试使用response.json()函数,但无济于事
fetch(`http://someserver `, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Accept-Language': 'ru,en;q=0.9',
},
body: '{"login":"root","password":"root"}'
})
.then((response) => {
console.log(response.json());
});
我得到的答复是这样的:
{
"type": "default",
"status": 200,
"ok": true,
"headers": {
"map": {
"x-xss-protection": "1",
"set-cookie": "jwt=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyLWNvZGUiOiJyb290LXVzZXIiLCJleHAiOjE1NTU0MjY0Mjl9.UaHzsIil8t9HtgrBF8JN0c2W-eIIkDEmb6GvO9Do0-A;Expires=Tue, 16 Apr 2019 14:53:49 +0000;Path=/;HttpOnly;SameSite=Strict",
"connection": "keep-alive",
"content-length": "360",
"content-type": "application/json;charset=utf-8",
"date": "Tue, 16 Apr 2019 13:53:49 GMT",
"server": "nginx/1.15.10"
}
},
"url": "***",
"_bodyInit": {
"_data": {
"size": 360,
"offset": 0,
"blobId": "3397402a-12dd-4dd9-8980-90924aeb416d"
}
},
"_bodyBlob": {
"_data": {
"size": 360,
"offset": 0,
"blobId": "3397402a-12dd-4dd9-8980-90924aeb416d"
}
}
}
我得到了bodyBlob,而不是正常的bodyText
答案 0 :(得分:0)
对不起,答案迟到了。希望对其他人有帮助。 请注意,response.json()返回promise。
fetch(`http://someserver `, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Accept-Language': 'ru,en;q=0.9',
},
body: '{"login":"root","password":"root"}'
})
.then((response) => {
response.json().then(res => {
console.log(res);
})
});