简体   繁体   English

c#httpclient-禁用ntlm

[英]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.第三方服务器是一个设备,他们最近打开了 NTLM。 Starting with the turning on of NTLM, my request now gets an HTTP 500 error error like this:从打开 NTLM 开始,我的请求现在收到 HTTP 500 错误错误,如下所示:

type Exception report message NTLM specified.类型 异常报告消息 NTLM 指定。 Downgraded to Basic Auth (and/or SSL) but downgrade not supported.降级到基本身份验证(和/或 SSL)但不支持降级。 description The server encountered an internal error that prevented it from fulfilling this request.说明 服务器遇到内部错误,无法完成此请求。 exception java.lang.UnsupportedOperationException: NTLM specified.异常 java.lang.UnsupportedOperationException:指定了 NTLM。 Downgraded to Basic Auth (and/or SSL) but downgrade not supported.降级到基本身份验证(和/或 SSL)但不支持降级。 net.sourceforge.spnego.SpnegoProvider.negotiate(SpnegoProvider.java:146) net.sourceforge.spnego.SpnegoAuthenticator.authenticate(SpnegoAuthenticator.java:271) net.sourceforge.spnego.SpnegoHttpFilter.doFilter(SpnegoHttpFilter.java:229) 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.我假设我的 httpclient 看到服务器现在支持 NTLM 并尝试执行 NTLM。 Is there any way to tell my httpclient to don't even bother with NTLM?有什么方法可以告诉我的 httpclient 甚至不要打扰 NTLM?

To disable NTLM try this:要禁用 NTLM,请尝试以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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