Java using HTTP client 4.5 client get statements

701 Views Asked by At

I am trying to update code from Apache HTTP client 3.1 to 4.5 and I have several methods like client.getHostConfiguration, client.getState,client.getHttpConnectionManager. All of these do not work in the newer versions of httpclient so I am wondering how to rewrite these. All I see in the HTTP client documentation is getParams. But I don't know how to get allthis other info from that.

If anyone wants the context that these are being used in

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

There are 1 best solutions below

0
On BEST ANSWER

Here's a modern proxy example for builing a Method:

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