在我的应用程序中,我想从服务器获取数据并将其显示在RecyclerView
中。
为了从服务器获取数据,我使用Retrofit2,并编写以下代码。
但是当应用程序运行一段时间后,在Retrofit2的onFailure
中会显示E/priceResLog:Err:SSL握手超时
!
我的代码:
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());
}
});
}
我该如何解决它?请帮助我,谢谢。