Ionic Native HTTP 不适用于 Anroid 9 (Pie) 及更高版本? [英] Ionic Native HTTP does not work for Anroid 9 (Pie) and up?

查看:19
本文介绍了Ionic Native HTTP 不适用于 Anroid 9 (Pie) 及更高版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序,该应用程序使用 Ionic Native HTTP 成功连接到我们的服务器,并使用三星 Galaxy J7 Prime 操作系统版本 Marshmallow 和其他几个尚未在 Android Pie 下进行测试.出于某种原因,当我使用 Android Pie 下的设备对其进行测试时,它不再起作用,并且我收到了 CORS 政策问题.有没有人遇到过类似的问题?有解决方法吗?不幸的是,服务器配置中的修改不是一种选择.我还阅读了一些有关代理的解决方案,但不确定如何实现它们.

I've created an app that connects successfully to our server using Ionic Native HTTP, testing it with Samsung Galaxy J7 Prime OS version Marshmallow and several others that were not yet under Android Pie. For some reason, when I tested it with a device under Android Pie, it won't work anymore and I'm receiving CORS policy issues. Has anybody encountered a similar issue? Is there a workaround for this? Unfortunately, modifications within the server config is not an option. I've also read some solutions about proxy but am not sure how to implement them.

版本:科尔多瓦插件-高级-http:2.1.1离子原生/http:5.8.0

Versions: cordova-plugin-advanced-http: 2.1.1 ionic-native/http: 5.8.0

推荐答案

Android P 默认需要 HTTPS.这意味着,如果您在应用中使用未加密的 HTTP 请求,则该应用在所有低于 Android P 的版本中都能正常运行.

Android P requires HTTPS by default. What this means is that if you are using unencrypted HTTP requests in your app, the app will work fine in all lower versions than Android P.

为避免此安全异常,请尝试在您的应用代码中进行以下更改.

To avoid this security exception, try below changes in your app code.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

并在 res/xml 添加名为:network_security_config.xml

and in res/xml add file named : network_security_config.xml

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        //  Add host of your download URL in below line. 
        //   ie. if url is  "https://www.google.com/search?source=...."
        //   then just add "www.google.com"
        <domain includeSubdomains="true">www.google.com</domain>
    </domain-config>
</network-security-config>

这篇关于Ionic Native HTTP 不适用于 Anroid 9 (Pie) 及更高版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆