Directly on the code:
ImportJava.io.BufferedReader;ImportJava.io.InputStreamReader;Importjava.net.InetSocketAddress;ImportJava.net.Proxy;ImportJava.net.URL;Importjava.net.URLConnection; Public classTrans {Static intTimeout = 10 * 1000;//in units of seconds StaticString host = "117.177.243.6";//117.177.243.7 Static intPort = 80; /*** Main Entrance method *@paramargs*/ Public Static voidMain (string[] args) {String URL= "Http://2018.ip138.com/ic.asp"; String result=get (URL); SYSTEM.OUT.PRINTLN (result); } /*** Request to send a GET method to the specified URL*/ Public Staticstring get (string url) {string result= ""; BufferedReader in=NULL; Try{URL Realurl=Newurl (URL); //creating a proxy serverInetsocketaddress addr =Newinetsocketaddress (host, Port); Proxy proxy=NewProxy (Proxy.Type.HTTP, addr);//HTTP Proxy//opening and linking between URLsURLConnection connection =realurl.openconnection (proxy); //to set common request propertiesConnection.setrequestproperty ("Accept", "*/*"); Connection.setrequestproperty ("Connection", "keep-alive"); Connection.setrequestproperty ("User-agent", "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) "); Connection.setrequestproperty ("Content-type", "application/x-www-form-urlencoded;"); Connection.setconnecttimeout (timeout); Connection.setreadtimeout (timeout); //establish an actual connectionConnection.connect (); //defines the response of the BufferedReader input stream to read the URLin =NewBufferedReader (NewInputStreamReader (Connection.getinputstream (), "GBK")); String Line; while(line = In.readline ())! =NULL) {result+=Line ; } } Catch(Exception e) {e.printstacktrace (); } finally { Try { if(In! =NULL) {in.close (); } } Catch(Exception e) {e.printstacktrace (); } } returnresult; }}
The above ip:117.177.243.6 and 117.177.243.7 is I temporarily find on the Internet two domestic proxy IP, you can also find yourself.
This address: http://2018.ip138.com/ic.asp is a domestic interface to obtain the client IP, you can see the effect by accessing this interface.
Java uses proxies to impersonate HTTP GET requests