I try to find out how to use httpclient with proxy and do not want to change java system property. But it seems that we can not find much document about it.
Finally, i have find out the solution:
First: Create httpclient
HttpClient client = new HttpClient();
set proxy
client.getHostConfiguration().setProxy(proxyhost, proxyPort);
//create authenticate
AuthScope auth = new AuthScope(proxyhost,proxyPort, AuthScope.ANY_REALM);
Credentials cred = new UsernamePasswordCredentials("","");
client.getState().setProxyCredentials(auth, cred);
=> now we can connect to internet through proxy.
If you want more information, please post comment. I will answer.
Saturday, April 12, 2008
How to use org.apache.commons.httpclient and excute method via proxy
Posted by CABA LAM at 7:07 AM 1 comments
Subscribe to:
Posts (Atom)