下面是我写的发送put请求的方法
'ConvertBack'
当我执行上述代码时,出现如下错误。我的目的是请求第三方支付接口
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;
}
我尝试替换多个 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
但没有替换。会不会是我的supportedProtocols
设置有误?
任何人都可以帮助我吗?非常感谢。