我正在创建授权应用程序,我正在使用 Retrofit 2。当我打电话时,它转到 onFailure 方法并得到异常
"javax.net.ssl.SSLException: Connection closed by peer"
但问题是,昨天这很好用。今天它给出了例外。我在互联网上发现一些SSLException - Connection closed by peer on Android 4.x 版本,或者这个How to add TLS v 1.0 and TLS v.1.1 with Retrofit,但这对我没有帮助。任何想法如何解决它。在后端启用 TLS1.2。
public class RegistrationFragment extends BaseFragment {
View mainView;
ApiClient apiClient = ApiClient.getInstance();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mainView = inflater.inflate
(R.layout.registration_fragment, container, false);
//Calling the authorization method
registerCall();
}
});
return mainView;
}
//User authorization method
public void registerCall() {
Call<ResponseBody> call = apiClient.registration(supportopObj);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
//Calling the clientCall method for getting the user clientID and clientSecret
Toast.makeText(getActivity(), "Registration Successful ",
Toast.LENGTH_SHORT).show();;
} else {
//if the response not successful
Toast.makeText(getActivity(), "Could not register the user maybe already registered ",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(getActivity(), "An error occurred", Toast.LENGTH_SHORT).show();
}
});
}
}