我繼承的代碼如何用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;
}
httpClient.getParams()
被@Deprecated和寫着「
HttpParams getParams()
Deprecated.
(4.3) use RequestConfig.
有用於RequestConfig沒有類的文檔,我不知道應該用什麼方法來代替getParams()
和ConnRoutePNames.DEFAULT_PROXY
謝謝;奧列格我只是重用你的答案[這裏](http://stackoverflow.com/questions/10297837/set-nonproxyhosts-in-apache-httpclient-4-1-3/32653727#32653727) – boly38