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