从Android 9 Pie开始,没有加密的请求永远不会起作用.默认情况下,系统会指望您默认使用TLS.您可以在此处阅读此功能因此,如果您只通过HTTPS发出请求,那么您就是安全的.但是那些通过不同网站提出请求的应用程序呢,例如类似浏览器的应用程序.
如何在Android 9 Pie中启用对HTTP和HTTPS的所有类型连接的请求?
java android kotlin android-network-security-config android-9.0-pie
升级到Cordova Android 8.0后,net::ERR_CLEARTEXT_NOT_PERMITTED尝试连接http://目标时出现错误。
为什么会这样,我该如何解决呢?
我正在使用Ionic-framework开发一个新应用,并且正在使用HttpClient模块来处理API请求。
问题是我已阅读并尝试将解决方案应用于:
但是我的应用程序在对API进行查询时始终抛出此错误。
这是我的文件的详细信息:
在/时,config.xml中:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
...
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:networkSecurityConfig="@xml/network_security_config"/>
<application android:usesCleartextTraffic="true" />
</edit-config>
<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
...
</widget>
Run Code Online (Sandbox Code Playgroud)
在/ resources / android / xml /中,network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
使用安全加密的协议HTTPS是无效的。该API仅允许使用HTTP。