How does httpurlconnection use a proxy server to connect to the Internet?

Source: Internet
Author: User
Tags bug id

Add
Properties prop = system. getproperties ();
System. getproperties (). Put ("proxyset", "true ");
// Set the address of the proxy server to be used for HTTP access
Prop. setproperty ("HTTP. proxyhost", "xxxxxxx ");
// Set the port for HTTP access to the proxy server to be used
Prop. setproperty ("HTTP. proxyport", "XXXXX ");

And then add
Prop. setproperty ("HTTP. proxyuser", "XXXXXXXX ");
Prop. setproperty ("HTTP. proxypassword", "XXXXX ");
Adding such content does not work. Instead, it uses "username: Password" for base64 encoding. The specific code is as follows:
String authentication = "username: Password ";
String encodedlogin = new base64encoder (). encode (authentication. getbytes ());
Httpurlconnection. setrequestproperty ("proxy-Authorization", "Basic" + encodedlogin );

Note base64encoder (). encode (authentication. getbytes (); base64encoder (). encodebuffer (authentication. getbytes () cannot be used here; otherwise, an error is returned.
For specific reasons, refer to the JDK bug published by Sun, Bug ID: 4615330 http://bugs.sun.com/bugdatabase/view_bug.do? Bug_id = 4615330

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.