Saturday, April 12, 2008

How to use org.apache.commons.httpclient and excute method via proxy

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.

2 comments:

Make money online | 0 investment | SEO said...

good post buddy

Anonymous said...

Hey,
I noticed that you have a nice tech blog here. I would like to introduce a service for bloggers named www.createlf.com that we launched recently. You can use createlf to enhance your blog in following ways:

1) Pick up good posts for your blog:

Createlf acts as place where you can choose to pick very good articles that you find here for your own blog occasionaly as guest posts. You can immediately start to look for new popular posts at: http://www.createlf.com. We make it easier for you to pick up posts since you have to simply copy paste javascript in your post section and article is posted on your blog.

2) Get Link Backs to your blog:

Whenever you post an article from createlf on your blog, a link to your blog is displayed on activity feeds in our main page and also with where ever the article is posted on any other blog!!!

Or you can be a contributor and:

3) Popularise your content:

You can become a source on createlf so that other bloggers can pick up your good articles and you can get lots of link backs and your content can get lots of views.

You can visit createlf.com or see how Createlf works at: http://www.createlf.com/index.php?page=how
So, we will appreciate if other then using it, you can write about our service on your blog.

Drop in a mail for any queries/suggestions!!

Thanks,
Asankhaya (asankhaya@createlf.com)
Mayank (mayank@createlf.com)
(Founders, Createlf.com)

Google