我尝试在React Native中使用fetsh()从外部服务器获取数据。我的查询看起来像这样:
fetch('https://xxx.xx/login.php', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: email,
password: password
})
}).then((response) => response.json())
.then((responseJson) => {
if(responseJson === 'Data Matched'){
this.props.navigation.navigate('Second', { Email: email});
}else{
Alert.alert(responseJson);
}
}).catch((error) => {
console.error(error);
return error;
});
在我的Android设备上执行过程中,出现以下错误:
Network request failed
Stack trace:
node_modules\whatwg-fetch\dist\fetch.umd.js:505:17 in setTimeout$argument_0
node_modules\react-native\Libraries\Core\Timers\JSTimers.js:135:14 in _callTimer
node_modules\react-native\Libraries\Core\Timers\JSTimers.js:387:16 in callTimers
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425:19 in __callFunction
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:6 in __guard$argument_0
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:4 in callFunctionReturnFlushedQueue
[native code]:null in callFunctionReturnFlushedQueue
...
当我在浏览器中打开文件时,一切正常,没有问题。
很高兴您的帮助。 非常感谢。 卢卡斯
答案 0 :(得分:0)
经过长时间的搜索,我现在找到了解决方案。通过对我的证书的https://www.ssllabs.com/ssltest进行的测试,我收到以下消息:
此服务器的证书链不完整。等级上限为B。
我将证书上传到https://certificatechain.io/,并将.crt文件添加到Web服务器上的SSL配置中。现在对我来说一切正常。
希望我可以帮助您。