【发布时间】:2019-10-19 01:30:56
【问题描述】:
我正在开发一个 React Native 应用程序。我正在使用 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"
});
预期的输出应该是应用程序允许我登录以获得正确的凭据,并在我输入错误凭据时给我“错误的电子邮件或密码”消息。而且我确实在调试中完美地得到了这个输出。该错误仅发生在 Release Apk 中。
【问题讨论】:
标签: javascript android react-native axios