With painstaking efforts, the common-http-client in Apache's common is studied in a simple way.ProgramTo connect to the Internet, it seems that the effect is good, you can use more in the future.
Because you need to use proxy servers to access the Internet at the company, there is no problem when trying to connect to the company's machines at the beginning of the HTTP-client experiment, it can be connected in a row. Later, the connection to the external site failed, saying it was inaccessible, that is, the reason why the proxy server was not used. After some investigation and research, we found thatCode.
Httpclient client = new httpclient ();
Client. gethostconfiguration (). sethost ("blog.csdn.net", 80, "HTTP ");
Client. getparams (). setcookiepolicy (
Cookiepolicy. browser_compatibility );
Client. gethostconfiguration (). setproxy ("172.16.1.21", 8080 );
Credentials defacreds = new usernamepasswordcredentials ("usrname ",
"Password ");
Client. getstate (). setproxycredentials (
New authscope ("172.16.1.21", 8080, null), defaultcreds );
Getmethod authget = new getmethod ("/dlxu ");
Client.exe cutemethod (authpost );
With the above code, you can construct a console program that accesses the HTTP site and bypass the proxy server.