安卓SSLHandshakeException连接被AsyncHttpClient或对等中的对等重置

时间:2018-09-21 13:00:52

标签: android retrofit retrofit2 sslhandshakeexception asynchttpclient

有人知道配置错误是什么吗,我得到了这样的异常:

javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0x71c528b200:
 I/O error during system call, Connection reset by peer 

以及如何为AsyncHttpClient(com.loopj.android:android-async-http:1.4.9)配置它?

我正在使用下一个配置:

 import com.loopj.android.http.AsyncHttpClient;
 import com.loopj.android.http.AsyncHttpResponseHandler;
 import com.loopj.android.http.PersistentCookieStore;
 import com.loopj.android.http.MySSLSocketFactory;
 import cz.msebera.android.httpclient.Header;
 import cz.msebera.android.httpclient.message.BasicHeader;

    public class ProductsRestService {

        public AsyncHttpClient getHttpClient() {

            AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
            asyncHttpClient.setCookieStore(new PersistentCookieStore(getContext()));
            KeyStore trustStore;
            try {
                trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
                trustStore.load(null, null);
                MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore);
                socketFactory.setHostnameVerifier(AppSSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

                asyncHttpClient.setSSLSocketFactory(socketFactory);
            } catch (Exception e) {
            }
            asyncHttpClient.setURLEncodingEnabled(true);
            return asyncHttpClient;
        }

    }

我发现这可能是TLS的不同版本,但是不确定如何配置异步客户端。

我在翻新中也尝试过:

Retrofit.Builder builder = new Retrofit.Builder()
                .baseUrl(HOST)
                .addConverterFactory(GsonConverterFactory.create());

        Retrofit retrofit = builder.build();

        RetrofitCallService callTokenService = retrofit.create(RetrofitCallService.class);

        Call<String> tokens = callTokenService.getToken();

        Headers headers = null;
        try {
            headers = tokens.execute().headers();
        } catch (IOException e) {
            e.printStackTrace();
        }


        List<String> values = headers.values("Content-Type");

结果相同。不确定我应该朝哪个方向搜索。

非常感谢您的帮助!

0 个答案:

没有答案