1

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 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.