Proxy doesn't work in HttpClient 4.0 beta2

Posted by shrimpy on Stack Overflow See other posts from Stack Overflow or by shrimpy
Published on 2009-05-17T08:21:38Z Indexed on 2010/06/06 22:02 UTC
Read the original article Hit count: 446

Filed under:
|

Hi,i am useing HttpClient 4.0-beta2, to do rest call, it works fine in my lap-top, but in uni, we have to config our application to go through a proxy, otherwise, we cannot connect to internet

Here is my orginal code:

HttpClient httpclient = new DefaultHttpClient();
HttpPut put = new HttpPut("http://" + PutBlob.ACCOUNT + ".blob.core.windows.net/container/abc");
put.addHeader(PutBlob.ContentType, PutBlob.CONTENT_TYPE.TEXT_PLAIN.getValue());
put.setEntity(new StringEntity("Hello world", "UTF-8"));
Sign(put, PutBlob.ACCOUNT, PutBlob.KEY);

log.debug(EntityUtils.toString(httpclient.execute(put).getEntity()));

And below is how i use proxy, but it didn`t work for me, what is the right way to config proxy in HttpClient4.0 ???

HttpHost hcProxyHost = new HttpHost("proxyserver", 3128, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, hcProxyHost);

HttpPut put = new HttpPut("/container/abc");
put.addHeader(PutBlob.ContentType, PutBlob.CONTENT_TYPE.TEXT_PLAIN.getValue());
put.setEntity(new StringEntity("Hello world", "UTF-8"));
Sign(put, PutBlob.ACCOUNT, PutBlob.KEY);

HttpHost target = new HttpHost( PutBlob.ACCOUNT + ".blob.core.windows.net");
log.debug(EntityUtils.toString(httpclient.execute(target, put).getEntity()));

© Stack Overflow or respective owner

Related posts about proxy

Related posts about httpclient