Java uses proxies to impersonate HTTP GET requests

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.