【发布时间】:2016-08-04 19:35:48
【问题描述】:
我对这个问题困惑了很久。尝试使用 React Native 的 fetch 向我的本地 HTTP 服务器发出 POST 请求,但不断得到 TypeError。
这是我如何处理我的请求。
onSignIn(credentials) {
const host = 'http://192.168.0.106';
const namespace = '/api/v1';
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
};
fetch(host + namespace + '/register', {
method: 'POST',
headers,
body: JSON.stringify(credentials)
}).then(res => res.json()).then(function (user) {
dispatch(registerSuccess(user));
}).catch(function (err) {
console.log(err);
dispatch(registerError(err));
});
}
我知道 IP 地址是正确的,因为我已在我的计算机上向 Postman 发出请求。我找到的答案也没有任何帮助我。我在 Android 5.1 上运行它,如果这有什么改变的话。
拜托,一点点帮助会大有帮助。
【问题讨论】:
-
您是在真实设备上进行测试吗?
-
是的,我是。确切地说,在小米 Note 3 Pro 上。
标签: android error-handling react-native fetch