請參閱「請求配置」部分here。總之:
1)建立你的客戶:
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setSocketTimeout(5000)
.setConnectTimeout(5000)
.setConnectionRequestTimeout(5000)
.setStaleConnectionCheckEnabled(true)
.build();
CloseableHttpClient httpclient = HttpClients.custom()
.(settingXY)
.setDefaultCookieStore(defaultCookieStore)
.setDefaultCredentialsProvider(defaultCredentialsProvider)
.setDefaultRequestConfig(defaultRequestConfig)
.setDefaultRequestConfig(defaultRequestConfig)
.build();
//You dont need to specify proxy here!!!
2)然後建立自己的reqeuest(S)是這樣的:
HttpGet httpget = new HttpGet("http://www.apache.org/");
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
.setProxy(new HttpHost("myproxy", 8080))
.build();
httpget.setConfig(requestConfig);
3)然後
defaultCredentialsProvider.setCredentials(new AuthScope(proxy.getHostName(), proxy.getPort()), proxyCredentials);
HttpGet httpget = new HttpGet("http://www.apache.org/");
HttpUriRequest request= httpget;
CloseableHttpResponse response = httpclient.execute(request, context);
希望這可以幫助某人。