【发布时间】:2017-04-27 21:14:45
【问题描述】:
我的本地服务器使用 wamp 服务器在 127.0.0.1:8080 上运行。 我尝试使用邮递员发布它,数据能够发布并保存到数据库。
但是当我尝试在 react native 中发布它时,它显示网络请求失败,如下所示
这是我的代码
fetch('http://127.0.0.1:8080/api/register', {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: this.state.name,
email: this.state.email,
password: this.state.password
})
})
.then((response) => response.json())
.then((responseData) => {
console.log(responseData.body)
})
.done();
如果我在我的电脑浏览器中输入地址 127.0.0.1:8080,它可以将我定向到我的本地主机页面。
但在我的模拟器中,我注意到它使用的是 LTE,当我使用浏览器访问 127.0.0.1:8080 时,它无法连接。按理说模拟器和我的电脑连接在同一个网络,应该可以访问吧?
我做错了吗?
【问题讨论】:
-
您是否尝试过使用 https 与 http 进行抓取?
-
嗨,Nader Dabit,我都试过了,都是一样的
-
您的 PC 和模拟器是两台不同的机器,即使模拟器是虚拟的。对于模拟器来说,127.0.0.1 是它本身,而不是 PC。您必须使用 PC 的实际地址。
标签: android react-native