【发布时间】:2019-11-17 17:47:14
【问题描述】:
我正在使用改造来解析 json 响应。但我收到失败响应。
这是我正在使用的 retrofitCallBack 方法,但我得到了 onFailure 响应。
private void retrofitCallBack() {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(SpinnerInterfaces.JSONURL)
.addConverterFactory(ScalarsConverterFactory.create())
.client(okHttpClient)
.build();
SpinnerInterfaces api = retrofit.create(SpinnerInterfaces.class);
Call<String> call = api.getJSONString();
final ProgressDialog progressDialog;
progressDialog = new ProgressDialog(SpinnerActivity.this);
progressDialog.setMessage(getString(R.string.loading_message));
progressDialog.setMax(100);
progressDialog.show();
call.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
Log.e("response","response"+response.body());
Log.e("response","response"+response.toString());
progressDialog.dismiss();
if (response.isSuccessful()) {
if (response.body() != null) {
String jsonresponse = response.body();
spinJSON(jsonresponse);
} else {
Toast.makeText(SpinnerActivity.this, getString(R.string.response_unsuccessful), Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
Log.e("response","response"+t);
Log.e("response","response"+call);
progressDialog.dismiss();
Toast.makeText(SpinnerActivity.this, getString(R.string.network_failed), Toast.LENGTH_SHORT)
.show();
}
});
}
下面是我正在使用的 SpinnerInterface。
public interface SpinnerInterfaces {
String JSONURL = "https://express-it.optusnet.com.au/";
@GET("sample.json")
Call<String> getJSONString();
}
这在一个月前有效,但是当我今天检查这个项目时突然它不起作用。
我正在使用的 Gradle 是:
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
我收到日志错误为:
responsejavax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0xe631cdf8: I/O error during system call, Connection reset by peer
responseretrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall@8cea2db
编辑:
我应用了这个answer,但我收到了日志错误
E/response: responsejava.net.SocketTimeoutException: SSL 握手超时
【问题讨论】:
-
@ADM 这不是重复的。我尝试了第一个答案。我收到日志错误作为 responsejava.net.SocketTimeoutException:SSL 握手超时。我编辑了我的答案。
标签: android android-studio gson retrofit retrofit2