0
我正在使用OkHttp 3.0.0-RC1進行Retrofit 2.0.0-beta3,並面臨以下小問題。與我使用CertificatePinner和OkHttp呼叫,但與改造調用即使我設置的是相同的客戶端在改造實例不起作用使用CertificatePinner改造okhttpclient
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
@Robert現在已經修復了,我在執行順序中發現了一個錯誤。我已經把我的答案放在下面 – dhaval