2015-06-19 140 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);