处于安全考虑,后台的所有请求都换成了https,但是,某些请求会出现和服务器整数认证不一致的情况,去找后台同事,不怎么上心,╮(╯▽╰)╭哎。。。。。。
只能使用以下方法
// Fresco 图片加载
X509TrustManager xtm =newX509TrustManager() {
@Override
public voidcheckClientTrusted(X509Certificate[] chain,String authType) {
}
@Override
public voidcheckServerTrusted(X509Certificate[] chain,String authType) {
}
@Override
publicX509Certificate[]getAcceptedIssuers() {
X509Certificate[] x509Certificates =newX509Certificate[0];
returnx509Certificates;
}
};
SSLContext sslContext =null;
try{
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, newTrustManager[]{xtm}, newSecureRandom());
}catch(NoSuchAlgorithmException e) {
e.printStackTrace();
}catch(KeyManagementException e) {
e.printStackTrace();
}
HostnameVerifier DO_NOT_VERIFY =newHostnameVerifier() {
@Override
public booleanverify(String hostname,SSLSession session) {
return true;
}
};
okHttpClient=newOkHttpClient().newBuilder()
.connectTimeout(10,TimeUnit.SECONDS)
.readTimeout(40,TimeUnit.SECONDS)
.writeTimeout(20,TimeUnit.SECONDS)
.sslSocketFactory(sslContext.getSocketFactory())
.hostnameVerifier(DO_NOT_VERIFY)
.build();
Set listeners =newHashSet<>();
listeners.add(newRequestLoggingListener());
ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
.newBuilder(this,okHttpClient)
.setDownsampleEnabled(true)
.setRequestListeners(listeners)
.build();
Fresco.initialize(this,config);
主要来自:https://www.fresco-cn.org/docs/using-other-network-layers.html
网友评论