maui中配置安卓手机在测试环境连接网络

非http

google在android p为了安全起见,已经明确规定禁止http协议额,但是之前很多接口都是http协议,我们一般是这样解决的: 在res目录下创建xml目录,然后随便创建一个.xml文件,里面内容如下: network_security_config

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
	<!-- 全局允许明文流量(仅调试用) -->
	<base-config cleartextTrafficPermitted="true" />

	<!-- 或者精确白名单 -->
	<!--
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">192.168.2.107</domain>
    <domain includeSubdomains="true">10.0.2.2</domain>
  </domain-config>
  -->
</network-security-config>

并且设置 生成操作为AndroidResource

在 然后在AndroidManifest.xml文件下 的 <application 节点 加入 android:networkSecurityConfig="@xml/network_security_config"


<application
    android:testOnly="false"
    android:name=".base.BaseApplication"
    android:allowBackup="true"
    android:configChanges="orientation|keyboardHidden"
    android:networkSecurityConfig="@xml/文件名"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning,UnusedAttribute"
    tools:replace="android:icon,android:label,android:theme,android:allowBackup,android:name">

高级见Android网络安全之NetworkSecurityConfig-CSDN博客