- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.net.UnknownHostException;
- /*
- *自定义客户端
- *服务端 tomcat
- *
- */
- public class MyIE {
- public static void main(String[] args) throws Exception, IOException {
- Socket s=new Socket("192.168.1.100",8080);
- PrintWriter out=new PrintWriter(s.getOutputStream(),true);
- out.println("GET /myweb/demo.html HTTP/1.1");
- out.println("Accept: */*");//什么都支持
- out.println("Accept-Language: zh-CN");//支持简体中文
- out.println("Connection: Keep-Alive");//加上后变慢。
-
- out.println();//一定要写空行,要和请求体分开。
- out.println(); //一定要写空行
- BufferedReader bufr=new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line=null;
- while((line=bufr.readLine())!=null){
- System.out.println(line);
- }
- s.close();
- }
- }
复制代码 |
|