【发布时间】:2018-12-01 13:06:54
【问题描述】:
在我的应用程序中,我想从服务器获取数据并将其显示到RecyclerView。
为了从服务器获取数据,我使用 Retrofit2 并编写以下代码。
但是一段时间后运行应用程序时,请从 Retrofit2 向我显示 onFailure 中的 E/priceResLog: Err : SSL handshake timed out!
我的代码:
public class ApiUtilsPrice {
private static final String BASE_URL = "https://core.arzws.com/";
private static Retrofit retrofit = null;
public static Retrofit getClient() {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.build();
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
活动代码:
private void getCoinData() {
loaderLayout(true);
Call<GoldListResponse> call = apiInterface.getGoldPrice();
call.enqueue(new Callback<GoldListResponse>() {
@Override
public void onResponse(Call<GoldListResponse> call, Response<GoldListResponse> response) {
if (response.isSuccessful()) {
if (response.body() != null) {
loaderLayout(false);
model.clear();
model.addAll(response.body().getGoldBoard());
coinAdapter.notifyDataSetChanged();
isSendApi = true;
}
}
}
@Override
public void onFailure(Call<GoldListResponse> call, Throwable t) {
Log.e("priceResLog", "Err : " + t.getMessage());
}
});
}
我该如何解决?请帮助我,谢谢。
【问题讨论】:
-
将超时时间从 60 增加到 90。
-
@HemantParmar,为什么?
-
服务器问题。正确链接您的证书。无需在 android 端进行更改。
-
改造需要添加默认证书
-
不要添加静态证书。