标签:
package servlet_01; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; public class Test { /**检测HTTP协议是什么一个东西 * @param args */ public static void main(String[] args) throws Exception { //连到tomcat Server Socket socket = new Socket("127.0.0.1", 8080); //拿到输出流 PrintWriter pw = new PrintWriter(new OutputStreamWriter( socket.getOutputStream())); pw.println("GET /aaa HTTP/1.1"); //GET+URL地址+HTTP/1.1,自己去看浏览器 pw.println("Host:localhost");//Host+域名 pw.println("Content-type:text/html"); pw.println(); //请求结束 pw.flush(); //输入流读取 BufferedReader br = new BufferedReader(new InputStreamReader( socket.getInputStream())); String str = ""; while ((str = br.readLine()) != null) { System.out.println(str); } br.close(); pw.close(); socket.close(); } }
读取tomcat的页面的html内容,了解HTTP协议。
标签:
原文地址:http://www.cnblogs.com/lihaoyang/p/4547939.html