我正在尝试将代码从Apache HTTP客户端3.1更新到4.5,我有几种方法,如client.getHostConfiguration
,client.getState
,client.getHttpConnectionManager
。所有这些都不适用于较新版本的httpclient,所以我想知道如何重写这些。我在HTTP客户端文档中看到的只是getParams。但我不知道如何从中获取所有其他信息。
如果有人想要在
中使用这些内容if(getProxy() != null) {
client.getHostConfiguration().setProxy(getProxy().getHost(),getProxy().getPort());
if (HttpProxyCredentials.isProxySet()) {
AuthScope authScope = new AuthScope(getProxy().getHost(), getProxy().getPort());
client.getState().setProxyCredentials(authScope, new NTCredentials(HttpProxyCredentials.getUserName(),
HttpProxyCredentials.getPassword(),
"",HttpProxyCredentials.getDomain()));
答案 0 :(得分:1)
这是构建方法的现代代理示例:
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.BEST_MATCH)
.setExpectContinueEnabled(true)
.setStaleConnectionCheckEnabled(true).setSocketTimeout(timeout)
.build();
if (proxyHost != null) {
defaultRequestConfig = RequestConfig.copy(defaultRequestConfig)
.setProxy(new HttpHost(proxyHost, proxyPort)).build();
}
method.setConfig(defaultRequestConfig);