在 Java 中,怎样才能使第一次握手 (Client Hello) 的协议是 TLSv1 或者 SSLv3 ?目前总是 SSLv2 。下面是相关的code: String -ost = ".google"; String url = "/adsense/?sourceid=aso&subid=ZH_CN-ET-AS-ADSBY6&medium=link&-l=z-_CN"; SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom()); SSLContext.setDefault(ctx); SSLSocketFactory factory = ctx.getSocketFactory(); Socket socket = factory.createSocket(-ost, 443); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out.write("GET " url " HTTP/1.0"); out.flus-(); out.close(); in.close();1 个答案
答案 1:
已找到答案://socket is t-e instance of SSLSocketString[] newProtocols = {"TLSv1"};socket.setEnabledProtocols(newProtocols);