Socket s = new Socket ("www.pconline.com.cn", 80 );
BufferedReader br = new BufferedReader (new InputStreamReader (s. getInputStream (), "GBK "));
OutputStream out = s. getOutputStream ();
StringBuffer sb = new StringBuffer ("GET/index.html HTTP/1.1 \ r \ n ");
Sb. append ("User-Agent: Java/1.6.0 _ 20 \ r \ n ");
Sb. append ("Host: www.pconline.com.cn: 80 \ r \ n ");
Sb. append ("Accept: text/html, image/gif, image/jpeg, *; q =. 2, */*; q =. 2 \ r \ n ");
Sb. append ("Connection: Close \ r \ n ");
Sb. append ("\ r \ n ");
Out. write (sb. toString (). getBytes ());
String tmp = "";
While (tmp = br. readLine ())! = Null ){
System. out. println (tmp );
}
Out. close ();
Br. close ();
} Catch (UnknownHostException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
} Www.2cto.com
Try {
Socket s = new Socket ("www.pconline.com.cn", 80 );
BufferedReader br = new BufferedReader (new InputStreamReader (s. getInputStream (), "GBK "));
OutputStream out = s. getOutputStream ();
StringBuffer sb = new StringBuffer ("GET/index.html HTTP/1.1 \ r \ n ");
Sb. append ("User-Agent: Java/1.6.0 _ 20 \ r \ n ");
Sb. append ("Host: www.pconline.com.cn: 80 \ r \ n ");
Sb. append ("Accept: text/html, image/gif, image/jpeg, *; q =. 2, */*; q =. 2 \ r \ n ");
Sb. append ("Connection: Close \ r \ n ");
Sb. append ("\ r \ n ");
Out. write (sb. toString (). getBytes ());
String tmp = "";
While (tmp = br. readLine ())! = Null ){
System. out. println (tmp );
}
Out. close ();
Br. close ();
} Catch (UnknownHostException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}