Import java. Io. bufferedinputstream;
Import java.net. url;
Import java.net. urlconnection;
Public class testproxyip {
Public static void main (string ARGs []) {
System. getproperties (). setproperty ("HTTP. proxyhost", "58.83.224.217 ");
System. getproperties (). setproperty ("HTTP. proxyport", "8080 ");
System. Out. println (gethtml ("http://iframe.ip138.com/city.asp"); // determines whether the agent is set successfully
}
Private Static string gethtml (string address ){
Stringbuffer html = new stringbuffer ();
String result = NULL;
Try {
URL url = new URL (Address );
Urlconnection conn = URL. openconnection ();
Conn. setrequestproperty ("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; gtb5;. Net CLR 2.0.50727; CBA )");
Bufferedinputstream in = new bufferedinputstream (conn. getinputstream ());
Try {
String inputline;
Byte [] Buf = new byte [1, 4096];
Int bytesread = 0;
While (bytesread> = 0 ){
Inputline = new string (BUF, 0, bytesread, "ISO-8859-1 ");
Html. append (inputline );
Bytesread = in. Read (BUF );
Inputline = NULL;
}
Buf = NULL;
} Finally {
In. Close ();
Conn = NULL;
Url = NULL;
}
Result = new string (html. tostring (). Trim (). getbytes ("ISO-8859-1"), "gb2312"). tolowercase ();
} Catch (exception e ){
E. printstacktrace ();
Return NULL;
}
Html = NULL;
Return result;
}
}
Running result:
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> your IP address </title>
</Head>
<Body style = "margin: 0px"> <center> your IP address is [58.83.224.217] From: Beijing 21 vianet </center> </body>