OkHTTP connection to PayPal gives an SSLHandshakeException
See original GitHub issueI’m using Java 1.8 and
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
To connect to Paypal via this code…
String httpUrl = "https://api.sandbox.paypal.com/retail/merchant/v1/invoices/";
String jsonContent = "{'test':'test'}";
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonContent);
Request request = new Request.Builder().url(httpUrl).post(requestBody).build();
Response response = new OkHttpClient().newCall(request).execute();
System.out.println(response.body());
I get the error response of…
main, READ: TLSv1 Alert, length = 2 main, RECV TLSv1 ALERT: fatal, handshake_failure main, called closeSocket() main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure main, called close() main, called closeInternal(true) Exception in thread “main” javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) at com.squareup.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192)
Can anyone help me out please.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7
Top GitHub Comments
try changing
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS)
toConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
(ConnectionSpec.MODERN_TLS) This works! THANK YOU!