JDK documentation rarely introduces the use of proxy servers. It is said that jdk5.0 seems to have added this content. In fact, it is very easy to use the proxy server, as long as you add the followingCodeYou can:
Properties prop =System. getproperties (); prop. Put ("HTTP. proxyhost", Getproxyhost (); prop. Put ("HTTP. proxyport", "" + getproxyport ());
That is, two items are added to the system variables.ProgramThe "-dhttp. proxyhost = xxx" parameter is also effective.
If the proxy server needs to be verified, use the following code:
String authentication = getproxyuser () + ":" +Getproxypassword (); string encodedlogin=NewSun. Misc. base64encoder (). encodebuffer (authentication. getbytes (); connection. setrequestproperty ("Proxy-Authorization", "Basic" + encodedlogin );
That is, the proxy-authorization information is added to the HTTP header.
More properties: http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html