日期:2014-05-17 浏览次数:20790 次
package cn.xxy.net.p7.ie_server;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class MyBrowser {
/**
* @param args
* @throws IOException
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException,IOException {
Socket s = new Socket("127.0.0.1", 80);
// 模拟浏览器,给tomcat服务端发送符合http协议的请求消息
PrintWriter out = new PrintWriter(s.getOutputStream());
out.println("GET /myweb/1.html HTTP/1.1");
out.println("Host: 127.0.0.1:80");
out.println("Connection: close");
out.println("Accept: */*");
out.println("Accept-Language: zh-CN");
out.println("User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; SE 2.X MetaSr 1.0)");
out.println("Accept-Encoding: gzip, deflate");
out.println();
out.println() ;
InputStream in = s.getInputStream();
byte b[] = new byte[1024];
int leng = 0;
while ((leng = in.read(b)) != -1) {
String str = new String(b, 0, leng);
System.out.println(str);
}
s.close();
}
}
out.println("GET /test/aa.jsp HTTP/1.1");
out.println("Host: 127.0.0.1");//这里就不用端口号了
out.println("Connection: close");
out.println("Accept: */*");
out.println("Accept-Language: zh-CN");
out.println("User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; SE 2.X MetaSr 1.0)");
out.println("Accept-Encoding: gzip, deflate");
out.println();