如何在 Android (9) Pie 中允许所有网络连接类型 HTTP 和 HTTPS? [英] How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

查看:21
本文介绍了如何在 Android (9) Pie 中允许所有网络连接类型 HTTP 和 HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从现在的 Android 9 Pie 开始,未加密的请求将永远无法工作.默认情况下,系统会希望您默认使用 TLS.您可以在此处阅读此功能 因此,如果您仅通过 HTTPS 发出请求,那么您是安全的.但是对于通过不同站点发出请求的应用程序(例如类似浏览器的应用程序)呢?

From Android 9 Pie now, requests without encryption will never work. And by default, the System will expect you to use TLS by default.You can read this feature here So if you only make requests via HTTPS you are safe. But what about apps that make requests through different sites, for instance, browser-like apps.

如何在 Android 9 Pie 中启用对所有类型连接 HTTP 和 HTTPS 的请求?

How can I enable requests to all types of connections HTTP and HTTPS in Android 9 Pie?

推荐答案

实现这一点的简单方法是将此属性用于您的 AndroidManifest.xml 中,您允许所有 http所有请求的代码>:

The easy way to implement this is to use this attribute to your AndroidManifest.xml where you allow all http for all requests:

<application android:usesCleartextTraffic="true">
</application>

但是,如果您想要一些更多配置用于不同的链接,例如,允许某些域的 http 而不是其他域,您必须提供 res/xml/networkSecurityConfig.xml 文件.

But in case you want some more configurations for different links for instance, allowing http for some domains but not other domains you must provide res/xml/networkSecurityConfig.xml file.

要在 Android 9 Pie 中执行此操作,您必须在 Manifest application 标记中设置 networkSecurityConfig,如下所示:

To do this in Android 9 Pie you will have to set a networkSecurityConfig in your Manifest application tag like this:

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




    </application>
</manifest>

然后在您的 xml 文件夹中,您现在必须创建一个名为 network_security_config 的文件,就像您在清单中命名的方式一样,然后从那里创建文件的内容应该像这样启用所有不加密的请求:

Then in your xml folder you now have to create a file named network_security_config just like the way you have named it in the Manifest and from there the content of your file should be like this to enable all requests without encryptions:

<?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>

从那里你可以开始了.现在您的应用程序将对所有类型的连接发出请求.有关此主题的更多信息阅读此处.

From there you are good to go. Now your app will make requests for all types of connections. For additional information on this topic read here.

这篇关于如何在 Android (9) Pie 中允许所有网络连接类型 HTTP 和 HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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