How to register AuthSchemes on HttpClient

I have this code

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getAuthSchemes().register("ntlm",new NTLMSchemeFactory());

However eclipse says DefaultHttpClient is deprecated and I replaced it with

HttpClient client = HttpClientBuilder.create().build();

However, now I do not have an api called getAuthSchemes (). So now with this new class, how do I register an auth schema?

I also found

ArrayList<String> authPrefs = new ArrayList<String>(2);
authPrefs.add(AuthSchemes.KERBEROS);
client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authPrefs);

but here also getParams and AuthPNames are deprecated.

So, what is not an outdated way to configure authentication schemes.

+4
source share
2 answers

The configuration is no longer performed on the client, but in the request, after you have HttpPost(or HttpGetsomething else), and before calling, execute()do the following:

HttpPost post = new HttpPost(...);

ArrayList<String> authPrefs = new ArrayList<String>();
authPrefs.add(AuthSchemes.NTLM);
authPrefs.add(AuthSchemes.KERBEROS);

// ...

RequestConfig config = RequestConfig.custom()
        .setProxyPreferredAuthSchemes(authPrefs).build();
post.setConfig(config);

// ....

client.execute(post);
+3
source

morgano, , NTLMTransport ksoap2 Windows/NTLM ( httpclient-4.3.1 httpcore-4.3, , = = 4.3).

DefaultHttpClient client = new DefaultHttpClient();

public static HttpPost httppost;
public static HttpClient client;

"", HttpPost "" setHeaders

//....
httppost = new HttpPost(url);
client = HttpClientBuilder.create().build();
ArrayList<String> authPrefs = new ArrayList<String>();
authPrefs.add(AuthSchemes.NTLM);
authPrefs.add(AuthSchemes.KERBEROS);
RequestConfig config = RequestConfig.custom().setProxyPreferredAuthSchemes(authPrefs).build();
httppost.setConfig(config);
//....

setupNtlm getAuthSchemes

client.getAuthSchemes().register("ntlm",new NTLMSchemeFactory());

authPrefs HttpGet ( , HttpPost HttpGet authPrefs client.execute)

HttpGet httpget = new HttpGet(url);
ArrayList<String> authPrefs = new ArrayList<String>();
authPrefs.add(AuthSchemes.NTLM);
authPrefs.add(AuthSchemes.KERBEROS);
RequestConfig config = RequestConfig.custom().setProxyPreferredAuthSchemes(authPrefs).build();
httpget.setConfig(config);

, , HttpEntity.consumeContent(), API 23.

0

Source: https://habr.com/ru/post/1533649/


All Articles