【问题标题】:Getting bodyUsed of Undefined error获取未定义错误的bodyUsed
【发布时间】:2017-12-29 09:42:05
【问题描述】:

我对 react-native 很陌生,我已经编写了登录代码

payload={email:"niju1992@gmail.com",password:"helo123"};
            var Options=
            {
              method: 'POST',
              headers: {'Accept': 'application/json','Content-Type': 'application/json'},
              body: payload 
            }

            fetch(Conf.API.SIGNIN, Options)
            .then((response) => 
              {
                if (response.status >= 400)
                {
                    throw new Error("Bad response from server");
                }
                return response.json();
              })
            .then((responseData) => 
            {
              //this.setState({data:responseData})
              console.log(responseData)  
            }) 
            .catch((error) => {
                  console.error("Error:"+error);
              })
            .done(); 

但是我遇到错误

index.android.bundle:19291 错误:TypeError:无法读取属性 'bodyUsed' 未定义

任何专家都可以。有人可以帮忙吗?

【问题讨论】:

  • 在你的项目目录中搜索bodyUsed,你粘贴的代码没有那个。
  • bodyUsed 在哪里使用?
  • 我没有在任何地方使用过bodyUsed
  • 我发现 Conf.API.SIGNIN 没有定义。一旦我定义了那个 URL,它就开始工作了。 谢谢大家

标签: node.js reactjs react-native


【解决方案1】:

在这里明确一点,问题是fetch 的输入 URL 的值为 undefined

这可能会导致如下异常:

TypeError: Cannot read property 'bodyUsed' of undefined at new Request

确保fetch 的第一个参数已定义!
否则你会遇到一些难以理解的错误。

【讨论】:

  • +1。在我的例子中,我有一个保存 URL 的对象,但我没有使用 foo.bar.url,而是使用了不存在的 foo.url
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多