[英]Blob Data error when fetching react-native
I am using react native to make a chat-like app. 我正在使用本机反应来制作类似聊天的应用程序。 Postman is working properly while doing all the requests I made possible in .NET core api.
在执行我在.NET Core API中实现的所有请求时,邮递员工作正常。 But when I am trying to fetch from react native it gives the following error:
但是,当我尝试从本地响应获取时,出现以下错误:
"null is not an object (evaluating 'blob.data')" “ null不是对象(评估'blob.data')”
I have tried to look into this issue in different articles but haven't found anything 我尝试在其他文章中研究此问题,但未发现任何问题
return new Promise((resolve, reject) => {
fetch('https://localhost:44305/api/replies', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(qId)
})
.then(res => res.json())
.then(result => resolve(result))
.catch(err => reject(err))
})
I am trying to get a list of answers to a question. 我正在尝试获取问题答案的列表。 Doing it from Postman works fine.
从邮递员那里做的很好。 I can't find a solution for this error.
我找不到此错误的解决方案。
I have tried adding return, just like somebody mentioned in a comment before fetch. 我尝试添加return,就像在获取之前在评论中提到的人一样。 The result is the same..
结果是一样的..
Thank you in advance! 先感谢您!
I thing your code must something like this: 我认为您的代码必须是这样的:
return fetch(
'https://localhost:44305/api/replies', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(qId)
}
)
.then(res => res.json())
.then(result => console.log(result))
.catch(err => console.log(err));
You don't need to create a new promise 'cause fetch
does it already. 您不需要创建新的诺言,因为
fetch
已经做到了。
Note console.log
is a void. 注意
console.log
是无效的。 That means if you continue with thening the null exception will occure again. 这意味着,如果继续进行调零,则将再次发生null异常。 To solve that use this code at the second then and catch callback method.
为了解决这个问题,请在第二个代码中使用此代码,然后捕获回调方法。
console.log(result);
return result;
解决了,问题是我的虚拟设备上没有访问localhost
权限,所以我所做的是将IP adress
从API中的Debugger选项更改为local ip adress
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.