The following is a method I wrote to send a put request
public static String doPut(String url, String jsonStr) {
// System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
CloseableHttpResponse httpResponse = null;
CloseableHttpClient httpClient = null;
try{
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new
File("C:\Users\wangyi\Desktop\stp_test_key\empresaca.keystore"));
keyStore.load(instream, "123456".toCharArray());
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(keyStore, "123456".toCharArray()).build();
SSLConnectionSocketFactory sslcsf = new SSLConnectionSocketFactory(
sslContext
,new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}
,new String[]{"SSL_RSA_WITH_RC4_128_SHA"}
, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
httpClient = HttpClients.custom().setSSLSocketFactory(sslcsf).build();
HttpPut httpPut = new HttpPut(url);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(35000)
.setConnectionRequestTimeout(35000)
.setSocketTimeout(60000).build();
httpPut.setConfig(requestConfig);
httpPut.setHeader("Content-type", "application/json");
httpPut.setHeader("DataEncoding", "UTF-8");
httpPut.setEntity(new StringEntity(jsonStr));
httpResponse = httpClient.execute(httpPut);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
return result;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpResponse != null) {
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
When I execute the above code, the following error appears 。My purpose is to request a third-party payment interface
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites
are inappropriate)
at sun.security.ssl.Handshaker.activate(Handshaker.java:554)
at sun.security.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1495)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1416)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1400)
at
org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at com.jyg.demo.stp.Main.doPut(Main.java:86)
at com.jyg.demo.stp.Main.enviaPago(Main.java:51)
at com.jyg.demo.stp.Main.main(Main.java:29)
Disconnected from the target VM, address: '127.0.0.1:61202', transport: 'socket'
Process finished with exit code 0
I tried to replace multiple supportedProtocols
but none of them. Could it be that my supportedCipherSuites
setting is wrong?
Anyone can help me ? Thanks a lot.
question from:
https://stackoverflow.com/questions/65952523/java-put-request-javax-net-ssl-sslhandshakeexception-no-appropriate-protocol 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…