java https_JAVA HTTPS

JDK与HTTPS各版本对应关系

967220a263368b0e0f1b689da2bdeb0b.png

IBMJDK 支持 TLS12

-Dcom.ibm.jsse2.overrideDefaultTLS=true

-Dcom.ibm.jsse2.overrideDefaultProtocol=TLSv12

#使用工具测试

D:\JDK\IBMJDK1.8_Win\bin>java.exe HTTPSClient baidu.com

HTTP/1.1 302 Moved Temporarily

Server: bfe/1.0.8.18

Date: Wed, 26 Aug 2020 05:58:37 GMT

Content-Type: text/html

Content-Length: 161

Connection: close

Location: http://www.baidu.com/error.html

Set-Cookie: __bsi=14235882381431070594_00_218_N_N_0_0303_C02F_N_N_N_0; expires=Wed, 26-Aug-20 05:58:42 GMT; domain=www.baidu.com; path=/

302 Found

302 Found


bfe/1.0.8.18

IBMJDK1.6-Win\bin>java.exe -Djdk.tls.client.protocols=TLSv1.2 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr ClientHello

2020-8-26 14:01:35 java.util.prefs.WindowsPreferences

WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

IBMJSSE2 to send SCSV Cipher Suite on initial ClientHello

*** ClientHello, TLSv1

IBMJDK1.8_Win\bin>java.exe -Djdk.tls.client.protocols=TLSv1.1 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr Hello

*** ClientHello, TLSv1.1

IBMJDK1.8_Win\bin>java.exe -Djdk.tls.client.protocols=TLSv1.2 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr Hello

*** ClientHello, TLSv1.2

IBMJDK1.8_Win\bin>java.exe -Dhttps.protocols=TLSv1.1 -Djavax.net.debug=ssl:handshake:verbose HTTPSClient baidu.com |findstr Hello

*** ClientHello, TLSv1.2

import java.net.*;

import java.io.*;

import java.security.*;

import javax.net.ssl.*;

public class HTTPSClient {

public static void main(String[] args) {

if (args.length == 0) {

System.out.println("Usage: java HTTPSClient host");

return;

}

int port = 443; // default https port

String host = args[0];

try{

//Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();

SSLSocket socket = (SSLSocket) factory.createSocket(host, port);

Writer out = new OutputStreamWriter(socket.getOutputStream());

// https requires the full URL in the GET line

out.write("GET / HTTP/1.0\\r\\\n");

out.write("\\r\\n");

out.flush();

// read response

BufferedReader in = new BufferedReader(

new InputStreamReader(socket.getInputStream()));

int c;

while ((c = in.read()) != -1) {

System.out.write(c);

}

out.close();

in.close();

socket.close();

}catch (IOException e) {

System.err.println(e);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值