我正在开发 React Native App。我正在使用 Axios 对 PHP Laravel 中的服务器进行 api 调用。如果我使用调试版本运行应用程序,一切都会按预期进行。我可以毫无问题地调用服务器。当我尝试发布 apk 时,Axios 总是给出“网络错误”的状态为 0。我已经确认我在服务器上也没有收到任何请求。但这仅发生在 Release apk 中。
我使用本地 ip 192.168.0.112,服务器在端口 80 上运行。我也尝试了不同的端口,但无济于事。问题是,如果我可以在调试 apk 中调用服务器,那么发布 apk 会立即给出“网络错误”有什么问题?
//这是我在用户第一次启动应用程序时进行的第一个调用 // 按下登录按钮,这是失败的地方,catch 中的代码运行。
Axios.post(server + "app/login", {
email: user.userEmail.toLowerCase(),
password: user.userPassword
})
.then(function(response) {
//This part doesn't run in release but works fine in debug
if (response.data.access_token.length) {
//Do Stuff If Logged In
}
})
.catch(function(error) {
//This is always executed in release as soon as the request is made
//i.e as soon as I press login button to login
console.log(error.request.status, error.config.url);
// Gives status = 0 and url "http://192.168.0.112/app/login"
});
预期的输出应该是应用程序让我登录以获取正确的凭据,并在我输入错误凭据时给我消息“错误的电子邮件或密码”。我确实在 Debug 中完美地得到了这个输出。该错误仅发生在 Release Apk 中。
相关分类