2015-06-19 235 views
1

我想從Apache HTTP客戶端3.1更新代碼到4.5,我有幾種方法,如client.getHostConfiguration,。所有這些都不適用於新版本的httpclient,所以我想知道如何重寫這些。我在HTTP客戶端文檔中看到的所有內容都是getParams。但我不知道如何從中得到所有這些信息。使用HTTP客戶端的Java 4.5客戶端獲取語句

如果有人想,這些都是在

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())); 

回答

1

正在使用的情況下下面是builing的方法的現代化代理例如:

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);