小编MGB*_*MGB的帖子

Axios Post 在调试中工作,但在 Android 发布版本中给出“网络错误”

我正在开发 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 …
Run Code Online (Sandbox Code Playgroud)

javascript android react-native axios

4
推荐指数
1
解决办法
5166
查看次数

标签 统计

android ×1

axios ×1

javascript ×1

react-native ×1