android9(api28),从Android 9(API级别28)开始,默认情况下禁用明文支持。

在生产环境中强制使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值