【问题标题】:Unexpected url in react-nativereact-native中的意外网址
【发布时间】:2018-04-02 09:55:28
【问题描述】:

我一直在使用 react-native 的 fetch 方法来调用 api,但不幸的是它说下面的意外 url 是我的代码

const myRequest = new Request("http://ipadress::portAddess/console/login/LoginForm.jsp", { method: 'GET' });

fetch(myRequest).then(response => {
  if (response.status === 200) {
      return response;
  } else {
       throw new Error('Something went wrong on api server!');
  }
}).then(response => {
   console.debug(response);
   // ...
}).catch(error => {
   console.error(error);
});

【问题讨论】:

  • 不确定,但可能:: 应该替换为:
  • @Vladyslav Matviienko 谢谢你,我没有注意到..现在它没有给出错误
  • 所以我的猜测是正确的?
  • @Vladyslav Matviienko 是的,你是对的..

标签: javascript android react-native fetch fetch-api


【解决方案1】:

你为什么在这里使用new Request

您必须将 url 和 params 直接传递给 fetch 函数。这是您的代码示例:

fetch("http://ipadress::portAddess/console/login/LoginForm.jsp", {
  method: 'GET',
})
.then(...)

【讨论】:

  • 然后检查您的网址。可能端口应该用:分隔,而不是::
猜你喜欢
  • 2019-07-18
  • 2015-06-01
  • 2016-07-16
  • 2016-11-04
  • 2020-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-18
相关资源
最近更新 更多