我正在使用HttpClient 4.0-beta2
, 进行 REST 调用。它在我的笔记本电脑上运行良好,但在 uni 中,我们必须配置我们的应用程序以通过代理,否则我们无法连接到互联网
这是我的原始代码:
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()));
下面是我如何使用代理,但它对我不起作用。
配置代理的正确方法是HttpClient 4.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()));