【发布时间】:2016-04-01 02:48:51
【问题描述】:
我正在使用带有 OkHttp 3.0.0-RC1 的 Retrofit 2.0.0-beta3 并面临以下微不足道的问题。我连接到的 HTTPS 服务器可以正常工作,我使用 CertificatePinner 和 OkHttp 调用,但不能使用 Retrofit 调用,即使我在 Retrofit 实例中设置相同的客户端
String hostname = "hostname";
CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add(hostname, "sha1/rNKiM/IsTzTMJ09jpMtPq4qP+Q8=")
.add(hostname, "sha1/hL8+j9RH89wlAW7eNDSS1ZlZ8Z8=")
.build();
OkHttpClient client = new OkHttpClient.Builder().certificatePinner(certificatePinner).build();
// This call works
OkHttpClient client = new OkHttpClient.Builder().certificatePinner(certificatePinner).build();
Request request = new Request.Builder()
.url("https://" + hostname + "/api/me")
.addHeader("Authorization", "Bearer token")
.build();
okhttp3.Call call = client.newCall(request);
//execute call returns 200 with response
// This is not working and throwing SSL Connection Error
retrofit = new Retrofit.Builder()
.baseUrl("https://" + hostname)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(client)
.build();
【问题讨论】:
-
“不起作用”是什么意思?
-
@Robert 现在已修复,我在执行顺序中发现了一个错误。我已经把我的答案放在下面了
标签: android retrofit okhttp retrofit2 okhttp3