OSX 上的 .Net Core 和 NTLM [英] .Net Core and NTLM on OSX

查看:93
本文介绍了OSX 上的 .Net Core 和 NTLM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .Net Core 应用程序(它是一个基于 NUnit 的集成测试),它使用 HttpClient 向服务器授权.服务器使用 NTLM 进行身份验证.

I have a .Net Core application (it is a NUnit based integration test) with authorizes with a server using HttpClient. The Server uses NTLM for authentication.

当我在 Windows 下运行这个测试时,它工作正常.当我在 OSX 下运行此测试时,它告诉我存在身份验证错误.

When I run this test under Windows, it works fine. When I run this test under OSX, it tells me that there are authentication errors.

当我使用 fiddler 观察流量时,我注意到服务器响应为401"并告诉客户端它可以使用 NTLM 进行身份验证.在 OSX 下,HttpClient 的反应是返回身份验证错误.

When I watch the traffic using fiddler, I notice that the server response witha "401" and tells the client that it can authenticate using NTLM. Under OSX the reaction of HttpClient is to return with authentication error.

OSX 不支持 NTLM 吗?我能以某种方式解决这个问题吗?

Is NTLM not supported for OSX? Can I fix this somehow?

推荐答案

我找到了解决方案,我需要这样做:

I found a solution, I need to do this:

        var credential = new NetworkCredential(userName, password, domain);
        var myCache = new CredentialCache();
        myCache.Add(new Uri(myURL), "NTLM", credential);

        var handler = new HttpClientHandler();

        handler.Credentials = myCache;

现在可以在 osx 下运行了!

Now it works under osx!

但它在 Windows 上停止工作:-).

But it stopped working on windows :-).

我可以做一个如果"来确定我是否在 osx 上...

I could do a "if" to determine if I am on osx or not ...

也许有更好的方法可以在 osx windows 上实现此功能?

Maybe there is a better way to make this work on osx and windows?

这篇关于OSX 上的 .Net Core 和 NTLM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆