Http.get() 工作但在 Ionic 4 的构建(发布/调试)中不起作用

2023-12-05

我正在尝试从一个简单的 api 获取数据,它在离子服务(浏览器),但是当我构建应用程序时,http 调用不起作用。我的代码是

this.http.get("http://example.com/api/routes").subscribe(response => {
 this.routes = response["routes"];
 for (let x in this.routes) {
 let a = this.routes[x].rou_stops;
 let b = a.split(",");
          for (let y in b) {
            this.newCit.push(b[y]);

          }
        }
   });

请帮助解决这个问题。


我猜你得到这个是因为 android 改变了它的 http 架构。

要使其在 Android 上运行,请转到项目根文件夹。

yourAppFolder > 资源 > android > xml > network_security_config.xml 将您的网络安全配置更改为熔断代码。

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Http.get() 工作但在 Ionic 4 的构建(发布/调试)中不起作用 的相关文章

随机推荐