Using Proxy in JAVA HTTP connection (httpurlconnection) and its validation (authentication)

Source: Internet
Author: User
Tags base64

Tag: Log print uses the type to verify the Encode base add password

 Public Static voidMain (string[] args) {//TODO auto-generated Method Stub         Try{URL URL=NewURL ("http://www.baidu.com"); //creating a proxy serverInetsocketaddress addr =NewInetsocketaddress ("172.21.1.8", 80); Proxy proxy=NewProxy (Proxy.Type.HTTP, addr);//HTTP ProxyURLConnection conn =url.openconnection (proxy); //The following three lines are required to enter your account password information when you need to verifyString Headerkey = "Proxy-authorization"; String Headervalue= "Basic" +base64.encodetostring ("Atco:atco". GetBytes (),false);//account password by: Separate, base64 encryption methodConn.setrequestproperty (Headerkey, Headervalue); InputStream in=Conn.getinputstream (); //InputStream in = Url.openstream (); String s = ioutils.tostring (in, "Utf-8");              System.out.println (s); } Catch(Exception e) {e.printstacktrace (); }      }

Using Proxy in JAVA HTTP connection (httpurlconnection) and its validation (authentication)

Related Article

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.