React native 反应本机获取-请求正文-意外的EOF
在我的react本机应用程序中,我试图使用React native 反应本机获取-请求正文-意外的EOF,react-native,fetch-api,React Native,Fetch Api,在我的react本机应用程序中,我试图使用body发出获取请求。但是,我收到了意外EOF的错误消息。实际上,请求是发出的,我的意思是我可以通过后端日志看到发送的请求,而在请求之后,它会显示错误消息 这是我的fetch方法 var Url = "https://----------"; return fetch(Url, { method: "POST", headers: { 'Accept': 'a
body
发出获取请求。但是,我收到了意外EOF
的错误消息。实际上,请求是发出的,我的意思是我可以通过后端日志看到发送的请求,而在请求之后,它会显示错误消息
这是我的fetch
方法
var Url = "https://----------";
return fetch(Url, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({'number': '11111111-'})
})
.then((response) => response.json())
.then((responseJson) => {
console.log("SEND_SMS RESULT: ",responseJson);
})
.done();
这是我得到的错误屏幕
我想说它在这一行失败:
response.json()
您确定您的响应是有效的JSON吗
尝试使用Postman测试响应,或者在
done()之前添加.catch(e=>console.log(e))
代码>我想说它在这一行失败:response.json()
您确定您的响应是有效的JSON吗
尝试使用Postman测试响应,或者在done()之前添加.catch(e=>console.log(e))
代码>
您的服务器返回的是null而不是error,很遗憾,response.json()无法对null响应进行操作
你可以简单地研究一下,关键词是“处理来自api的空响应”
您的服务器返回的是null而不是error,很遗憾,response.json()无法对null响应进行操作
你可以简单地研究一下,关键词是“处理来自api的空响应”
var Url = "https://----------";
return fetch(Url, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({'number': '11111111-'})
})
.then((response) => response.text())
.then((responseJson) => {
const resposeJson2 = responseJson.length ? JSON.parse(responseJson) : {};
console.log("SEND_SMS RESULT: ",responseJson2);
})
.done();