Retrofit - SSL库中的失败,通常是协议错误

时间:2016-06-14 13:30:16

标签: android ssl retrofit okhttp

我一直在尝试使用Retrofit向服务器发出请求,并且它一直在给我这个错误。

javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x60cc49f8: Failure in SSL library, usually a protocol error

此代码一直有效,直到现在,我没有触摸任何东西也没有改变任何东西,我想知道图书馆发生了什么。

见下文:

String BASE_URL = "https://api.example.com";

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        PayInterface service = retrofit.create(PayInterface.class);

        Call<PaymentData> call = service.getPost();
        call.enqueue(new Callback<PaymentData>() {

            @Override
            public void onResponse(Response<PaymentData> response, Retrofit retrofit) {
                // Get result Repo from response.body()
                // response.isSuccess() is true if the response code is 2xx

                int statusCode = response.code();
                if (response.isSuccess()) {

                    PaymentData post = response.body();
                    System.out.println("my post: "+post.getMessage());

                } else {
                    // handle request errors yourself
                    ResponseBody errorBody = response.errorBody();
                }

            }

            @Override
            public void onFailure(Throwable t) {
                System.out.println("failed: "+t);
            }
        });

我的界面:

public interface PayInterface {

    @Headers({
            "Key1: xxx",
            "Content-Type: application/json",
            "User-Agent: My-App-Name"
    })
    @POST("/path/another-path")
    Call<PaymentData>
    getPost();

}

依赖关系:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'

    compile 'com.google.code.gson:gson:2.4'
    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
    compile 'com.squareup.okhttp:okhttp:2.7.0'

}

拜托,有什么遗失的吗?

0 个答案:

没有答案