相关疑难解决方法(0)

如何用RequestConfig替换不推荐使用的httpClient.getParams()?

我继承了代码

import org.apache.http.client.HttpClient;
...
HttpClient httpclient = createHttpClientOrProxy();
...



private HttpClient createHttpClientOrProxy() {
    HttpClient httpclient = new DefaultHttpClient();

    /*
     * Set an HTTP proxy if it is specified in system properties.
     * 
     * http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
     * http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientExecuteProxy.java
     */
    if( isSet(System.getProperty("http.proxyHost")) ) {
        int port = 80;
        if( isSet(System.getProperty("http.proxyPort")) ) {
            port = Integer.parseInt(System.getProperty("http.proxyPort"));
        }
        HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost"), port, "http");
// @Deprecated methods here... getParams() and ConnRoutePNames
        httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    return httpclient;
}
Run Code Online (Sandbox Code Playgroud)

httpClient.getParams() 是@Deprecated并读"

HttpParams  getParams()
Deprecated. 
(4.3) use …
Run Code Online (Sandbox Code Playgroud)

java proxy apache-httpclient-4.x

17
推荐指数
2
解决办法
3万
查看次数

标签 统计

apache-httpclient-4.x ×1

java ×1

proxy ×1