标签:network this creat cli system uri timeout 调试 ogg
在生产环境中强制使用https,但在调试模式下允许使用明文的方法 它仅在api 23+上使用
在build.gradle中:
// Put this in your buildtypes debug section: manifestPlaceholders = [usesCleartextTraffic:"true"] // Put this in your buildtypes release section manifestPlaceholders = [usesCleartextTraffic:"false"]
在AndroidManifest.xml中的application标签中
android:usesCleartextTraffic="${usesCleartextTraffic}"
android:usesCleartextTraffic="true"
其它方法“
删除了这一行
android:networkSecurityConfig="@xml/network_security_config"
application
添加
android:usesCleartextTraffic="true"
改造配置类OKHttp创建时添加了一个连接规范
.connectionSpecs(CollectionsKt.listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT))
OkHttpClient okHttpClient = new OkHttpClient.Builder() .readTimeout(10, TimeUnit.SECONDS) .connectTimeout(10, TimeUnit.SECONDS) .cache(null) .connectionSpecs(CollectionsKt.listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT)) .addInterceptor(new NetworkInterceptor(context)) .addInterceptor(createLoggingInterceptor()) .addInterceptor(createSessionExpiryInterceptor()) .addInterceptor(createContextHeaderInterceptor()) .build();
<network-security-config> <base-config cleartextTrafficPermitted="true"> <trust-anchors> <certificates src="system" /> <certificates src="user" /> </trust-anchors> </base-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">api.endv.cn</domain> <domain includeSubdomains="true">im.endv.cn</domain> <domain includeSubdomains="true">pay.endv.cn</domain> <domain includeSubdomains="true">endv.cn</domain> </domain-config> </network-security-config>
从Android 9(API级别28)开始,默认情况下禁用明文支持。
标签:network this creat cli system uri timeout 调试 ogg
原文地址:https://www.cnblogs.com/endv/p/13262399.html