我使用 Retrofit2,当我尝试访问 https 协议时,它开始发誓,我如何才能将证书连接到它?在网上,我找到了类似这样的代码:
OkHttpClient okHttp = new OkHttpClient();
okHttp.setSslSocketFactory(getSSLConfig(contex).getSocketFactory());
Retrofit retrofit = builder.client(okHttp).build();
retrofit.create(serviceClass)
我连接了但是......我没有OkHttp在那里找到方法。setSslSocketFactory
PS 连接 OkHttp 来自:
编译'com.squareup.okhttp3:okhttp:3.6.0'
资料来源:
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("https://site.cf")
.addConverterFactory(GsonConverterFactory.create(gson));
CertificatePinner certificatePinner = new CertificatePinner.Builder().add("site.cf","sha256/key").build();
OkHttpClient client = new OkHttpClient.Builder()
.certificatePinner(certificatePinner)
.build();
Retrofit retrofit = builder.client(client).build();
API api = retrofit.create(API.class);
在 okhttp3 中朝 CustomTrust 的方向看一些东西(我正在通过电话写信,很难搜索 :)。和谷歌如何使用它进行自签名
PS 该死的,因为答案已发布...