【问题标题】:IONIC http.get is hanging on emulator or device but working on browserIONIC http.get 挂在模拟器或设备上,但在浏览器上工作
【发布时间】:2020-03-04 14:06:47
【问题描述】:

我们有一个 IONIC 应用程序,我们在其中调用外部服务女巫发布带有数据的 JSON 对象。

当我们通过 > ionic serve 执行 de app 时,在浏览器上一切正常,但是当我们尝试在模拟器上执行时,执行 get 后什么都没有发生。

我们称之为:

//we pop a message just here, and the device shows it.
  this.http.get('https://ourExternalSite.com/getData').subscribe(data => {
    //do things. We put here a message that never pops
  }, error => {
   //do things, we also put here a message, that never pops neither
  });

我们检查了设备上的https://ourExternalSite.com/getData url,完全可以访问并显示 JSON 对象。

我们不是 IONIC 方面的专家,此应用是由分包商开发的,我们正在尝试将其集成到我们的环境中。

编辑:我尝试将 network_security_config.xml 文件添加到项目中,正如这些答案所建议的那样:Http.get() working but not working in build(Release/Debug) in Ionic 4 Ionic Native HTTP does not work for Anroid 9 (Pie) and up?

但没有任何改变

EDIT2:好的,我缩小了问题的范围。必须使用 https,如果我将调用更改为 http 请愿书,一切正常!

所以我想我需要在 network_security_config.xml 文件中启用 https 调用

任何帮助将不胜感激。

【问题讨论】:

标签: android cordova http ionic-framework get


【解决方案1】:

好的,最后我解决了混合 Najam 提出的答案并添加的问题

<trust-anchors>
     <certificates src="@raw/external_site_certificate"/>
</trust-anchors>

到我的 network_security_config.xml,其中 external_site_certificate 是我尝试拨打电话的站点的公钥证书。

【讨论】:

    猜你喜欢
    • 2017-03-02
    • 2014-06-08
    • 2019-11-23
    • 2021-05-25
    • 2012-08-19
    • 2023-03-23
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多