简体   繁体   中英

c# httpclient - disable ntlm

I'm using this code to connect to a third party server.

using (HttpClientHandler httpClientHandler = new HttpClientHandler())
{
    httpClientHandler.AllowAutoRedirect = false;
    httpClientHandler.Credentials = new NetworkCredential(login, password);
    using (HttpClient authClient = new HttpClient(httpClientHandler))
    {
        response = await authClient.GetAsync(authenticationUrl).ConfigureAwait(false);
        ... response processing here
    }
}

The third party server is an appliance, and they've turned on NTLM recently. Starting with the turning on of NTLM, my request now gets an HTTP 500 error error like this:

type Exception report message NTLM specified. Downgraded to Basic Auth (and/or SSL) but downgrade not supported. description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.UnsupportedOperationException: NTLM specified. Downgraded to Basic Auth (and/or SSL) but downgrade not supported. net.sourceforge.spnego.SpnegoProvider.negotiate(SpnegoProvider.java:146) net.sourceforge.spnego.SpnegoAuthenticator.authenticate(SpnegoAuthenticator.java:271) net.sourceforge.spnego.SpnegoHttpFilter.doFilter(SpnegoHttpFilter.java:229)

I'm assuming my httpclient sees that the server now supports NTLM and tries to do NTLM. Is there any way to tell my httpclient to don't even bother with NTLM?

To disable NTLM try this:

        var modules = AuthenticationManager.RegisteredModules;
        while (modules.MoveNext())
        {
            var module = (IAuthenticationModule) modules.Current;
            if (module.AuthenticationType == "NTLM")
            {
                AuthenticationManager.Unregister(module);
                break; 
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM