Http.get() 在 Ionic 4 的构建(发布/调试)中工作但不工作 [英] Http.get() working but not working in build(Release/Debug) in Ionic 4
本文介绍了Http.get() 在 Ionic 4 的构建(发布/调试)中工作但不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从一个简单的 api 获取数据,它在 ionic serve(browser) 中工作正常,但是当我构建应用程序时,http 调用不起作用.我的代码是
I am trying get data from a simple api, it works fine in ionic serve(browser) , But when i build the app http call does not work. my Code is
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 架构.
I am Guessing that your are getting this because of android changes its http architecture.
要使其在 Android 上运行,请转到您的项目根文件夹.
to make it working on Android go to your project root folder.
yourAppFolder > 资源 > android > xml > network_security_config.xml将您的网络安全配置更改为打击代码.
yourAppFolder > resources > android > xml > network_security_config.xml Change your network security config to blow code.
<?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>
这篇关于Http.get() 在 Ionic 4 的构建(发布/调试)中工作但不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文