在生产环境中强制使用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();
api.endv.cn
im.endv.cn
pay.endv.cn
endv.cn
来源:https://www.cnblogs.com/endv/p/13262399.html