我有一个Java实现,各种客户端应用程序使用它来连接到第三方系统。这些第三方系统通过http / https支持不同的协议。在这种情况下,所有客户端应用程序都托管在Java实现所在的同一服务器上。因此,在这种情况下,各种客户端应用程序会为系统属性设置各种https协议(例如:System.setProperty("https.protocols", "SSLv3"),System.setProperty("https.protocols", "TLS")当它们使用此协议连接到那些第三方系统时)。
在这里,系统属性在该环境中的所有应用程序之间共享。因此,修改System属性会导致许多问题。所以,我想知道
blogs.oracle.com中提到的每个JDK版本都支持的协议和算法:

代码:
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();
}
Run Code Online (Sandbox Code Playgroud)
我的Java版本:1.5
我建议你根本不要设置它。只需让系统与对等方协商即可。它将协商最强的共享协议。
| 归档时间: |
|
| 查看次数: |
24634 次 |
| 最近记录: |