telnet获取网页过程

客服端-服务器模式

TCP/UDP

telnet下载网页

 

telnet获取网页过程

步骤1: telnet www.baidu.com 80(设置目标服务器, 端口号)

步骤2: GET /index.html HTTP/1.1

Host: www.baidu.com

步骤3:然后连续按两下enter键盘, 获取网页结果

再进一步,使用Java获取网页

BufferedWriter bw =null;

BufferedReader br = null;

 

// 步骤1 telnet www.baidu.com 80(设置目标服务器, 端口号)

Socket socket = new Socket(url,80);

 

// 步骤2

// GET /index.html HTTP/1.1

// Host: www.baidu.com

bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

bw.write("GET /"+ mainPage + " HTTP/1.1\r\n");

bw.write("HOST:" + url + "\r\n");

bw.write("\r\n");//HTTP head end!

bw.flush();

 

//步骤3

//然后连续按两下enter键盘, 获取网页结果

br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));

String line ;

while((line = br.readLine())!=null){

System.out.println(line);

}

 

if(bw != null){

bw.close();

}

if (br != null) {

br.close();

}

if(socket != null)

{

socket.close();

}

上一篇:京东js加密 nloginpwd 破解


下一篇:IO流