java – 为HTTPS连接设置https.protocols系统属性的问题

我有一个 Java实现,它被各种客户端应用程序用来连接到第三方系统.这些第三方系统通过http / https支持不同的协议.在这种情况下,所有客户端应用程序都托管在我的Java实现托管的同一服务器中.因此,在这种情况下,各种客户端应用程序将各种https协议设置为系统属性(例如:System.setProperty(“https.protocols”,“SSLv3”),System.setProperty(“https.protocols”,“TLS”)他们正在使用它连接到那些第三方系统.

此处,系统属性在该环境中的所有应用程序之间共享.因此,修改系统属性会导致许多问题.所以,我想知道,

>有没有办法在不使用系统属性的情况下完成此操作?
>有没有办法设置所有可能的https.protocols,以便它
支持与第三方建立的任何http或https连接
系统支持各种协议?

在blogs.oracle.com中提到的每个JDK版本中支持的协议和算法:
《java – 为HTTPS连接设置https.protocols系统属性的问题》

代码:

String responseStr = null;

System.setProperty("https.protocols",http-protocol); // This is set by the client applications. Previously, there was one by one (eg : "SSLv3". Then I changed it to "TLSv1.2,TLSv1.1,TLSv1,SSLv3" assuming it will enable all) 

byteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byteArrayOutputStream.write(requestStr.getBytes());

URL mUrl = new URL(proxy_url);
HttpURLConnection con = (HttpURLConnection) mUrl.openConnection(); // It works fine for the HttpURLConnection when there's no (s)

con.setRequestMethod("POST");
con.setDoOutput(true);
con.setUseCaches(false);
con.setDoInput(true);

con.setRequestProperty("user-agent","Mozilla(MSIE)");
con.setRequestProperty("Accept-Encoding","gzip,deflate");

byteArrayOutputStream.writeTo(con.getOutputStream());

String encodingHeader = con.getHeaderField("Content-Encoding");
InputStream inputStream = null;

if(encodingHeader != null && encodingHeader.toLowerCase().indexOf("gzip") != -1){
    inputStream = new GZIPInputStream(con.getInputStream());
}else {
    inputStream = con.getInputStream();

}

if (inputStream != null) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
       byte[] buffer = new byte[4096];
       int length = 0;

       while ((length = inputStream.read(buffer)) != -1) {
           baos.write(buffer, 0, length);
       }

    responseStr = new String(baos.toByteArray());
    baos.close();

 }

我的Java版本:1.5

最佳答案 我建议你根本不设置它.让系统与同行协商.它将协商最强大的共享协议.

点赞