Android React本机获取API仅在开发环境中工作
我使用FetchAPI从我的节点服务器检索数据,以响应本机应用程序。当我在Android Studio emulator或phsycal设备中执行应用程序时,它运行良好,但当我构建它以导出外部APK时,应用程序无法执行请求。类型错误:网络请求失败 这是本机的获取Android React本机获取API仅在开发环境中工作,android,node.js,react-native,fetch,Android,Node.js,React Native,Fetch,我使用FetchAPI从我的节点服务器检索数据,以响应本机应用程序。当我在Android Studio emulator或phsycal设备中执行应用程序时,它运行良好,但当我构建它以导出外部APK时,应用程序无法执行请求。类型错误:网络请求失败 这是本机的获取 NetInfo.fetch().then(state => { if (state.isConnected) { fetch('http://example/API2/clients', { method:
NetInfo.fetch().then(state => {
if (state.isConnected) {
fetch('http://example/API2/clients', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
nombre: this.state[key],
}),
})
.then(response => response.json())
.then(responseJson => {
console.log(responseJson);
})
.catch(error => {
console.log(error);
Alert.alert(
'Lo sentimos',
'No se ha recibido respuesta del servidor' + error,
);
});
} else {
Alert.alert('Sin conexión a internet', 'Verifique su conexión');
}
});
我注意到客户甚至都没有发出请求。
React本机版本:0.61我注意到问题出在服务器端,SSL证书工作不正常。React native的最新版本不允许没有此证书的请求
fetch('https://example/API2/clients', {
我还需要将http更改为https您是在尝试从本地服务器还是远程服务器获取数据?