SSL,Secure Sockets Layer,安全Socket層
TLS,Transport Layer Security,傳輸層安全協(xié)議
package network.secure; import java.io.*; import javax.net.ssl.*; public class HTTPSClient { public static void main(String[] args) { if (args.length == 0) { System.out.println("Usage: java HTTPSClient2 host"); return; } int port = 443; // default https port String host = args[0]; SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket socket = null; try { socket = (SSLSocket) factory.createSocket(host, port); // enable all the suites String[] supported = socket.getSupportedCipherSuites(); socket.setEnabledCipherSuites(supported); Writer out = new OutputStreamWriter(socket.getOutputStream(), "UTF-8"); // https requires the full URL in the GET line out.write("GET http://" + host + "/ HTTP/1.1 "); out.write("Host: " + host + " "); out.write(" "); out.flush(); // read response BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream())); // read the header String s; while (!(s = in.readLine()).equals("")) { System.out.println(s); } System.out.println(); // read the length String contentLength = in.readLine(); int length = Integer.MAX_VALUE; try { length = Integer.parseInt(contentLength.trim(), 16); } catch (NumberFormatException ex) { // This server doesn"t send the content-length // in the first line of the response body } System.out.println(contentLength); int c; int i = 0; while ((c = in.read()) != -1 && i++ < length) { System.out.write(c); } System.out.println(); } catch (IOException ex) { System.err.println(ex); } finally { try { if (socket != null) socket.close(); } catch (IOException e) {} } } }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/65957.html
摘要:單個(gè)請(qǐng)求范圍之外的異常可能會(huì)關(guān)閉服務(wù)器。客戶端可能超時(shí)或崩潰,用戶可能取消事務(wù),網(wǎng)絡(luò)可能在流量高峰期間癱瘓,黑客可能發(fā)動(dòng)拒絕服務(wù)攻擊。如果默認(rèn)長度不夠大,一些的構(gòu)造函數(shù)還允許改變這個(gè)隊(duì)列的長度,不能不能超過操作系統(tǒng)支持的最大值。 ServerSocket的生命周期 一個(gè)ServerSocket的基本生命周期:1)使用一個(gè)ServerSocket構(gòu)造函數(shù)在一個(gè)特定端口創(chuàng)建一個(gè)新的Serv...
摘要:上,數(shù)據(jù)按有限大小的包傳輸,這些包成為數(shù)據(jù)報(bào),每個(gè)數(shù)據(jù)報(bào)包含一個(gè)首部和一個(gè)有效載荷。不過,由于數(shù)據(jù)報(bào)長度有限,通常必須將數(shù)據(jù)分解為多個(gè)包,再在目的地重新組合。這兩個(gè)構(gòu)造函數(shù),在返回之前會(huì)與遠(yuǎn)程主機(jī)建立一個(gè)活動(dòng)的網(wǎng)絡(luò)連接。 Internet上,數(shù)據(jù)按有限大小的包傳輸,這些包成為數(shù)據(jù)報(bào)(datagram),每個(gè)數(shù)據(jù)報(bào)包含一個(gè)首部(header)和一個(gè)有效載荷(payload)。首部包含包發(fā)...
閱讀 1309·2021-09-22 15:00
閱讀 3313·2019-08-30 14:00
閱讀 1225·2019-08-29 17:27
閱讀 1225·2019-08-29 16:35
閱讀 693·2019-08-29 16:14
閱讀 2046·2019-08-26 13:43
閱讀 2125·2019-08-26 11:35
閱讀 2310·2019-08-23 15:34