Use Apache HTTP-client to bypass the Proxy Server

Source: Internet
Author: User

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.

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.