URL url=new URL("http://www.qy.com.cn/pdtshw/emlshw/index.asp");
Socket socket=new Socket(url.getHost(),80);
BufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out=new PrintWriter(socket.getOutputStream());
StringBuffer sb=new StringBuffer();
out.println("GET /"+url.getFile()+" HTTP/1.1");
out.println("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, */*");
out.println("Accept-Language: zh-cn");
out.println("deflateUser-Agent: Mozilla/4.0");
out.println("Host:"+url.getHost());
out.println("");
out.flush();
- 因为println是行输出,所以不用加/r/n,但如果write就是要了;
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
wr.write("GET / HTTP/1.0/r/n/r/n");
wr.flush();
- 在头文件的结尾处要加一个空行;用out.println(""); 或wr.write("/r/n");
- 最后要用out.flush(); 不发送数据;