Use proxies and their validation (authentication) in JAVA HTTP connections (httpurlconnection) __java

Source: Internet
Author: User
public static void Main (string[] args) {
		//TODO auto-generated method stub
		 try {
	            url url = new URL ("Http://ww W.baidu.com ");
	            Create a proxy server
	            inetsocketaddress addr = new Inetsocketaddress ("172.21.1.8");
	            Proxy proxy = new Proxy (Proxy.Type.HTTP, addr); HTTP proxy
	            URLConnection conn = url.openconnection (proxy);

                    The following three lines are in need of authentication, enter account password information
	            String headerkey = "Proxy-authorization";
	            String headervalue = "Basic" +base64.encodetostring ("Atco:atco". GetBytes (), false);	Account password: Separated, base64 encryption way
	            Conn.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 ();
	        }
	}

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.