Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 使用HttpClient在mac上的dotnet core应用程序中使用网络信任_Macos_.net Core_Httpclient_Ntlm_Httpclienthandler - Fatal编程技术网

Macos 使用HttpClient在mac上的dotnet core应用程序中使用网络信任

Macos 使用HttpClient在mac上的dotnet core应用程序中使用网络信任,macos,.net-core,httpclient,ntlm,httpclienthandler,Macos,.net Core,Httpclient,Ntlm,Httpclienthandler,编写dotnet核心应用程序。我需要使用网络凭据登录,因为服务(恰好是prem服务器上的TFS)使用这些凭据进行身份验证。在我(和另一个团队成员)的windows计算机上,以下代码起作用: Console.WriteLine("Type in your DOMAIN password:"); var pass = GetPassword(); //command line secure string magic from SO var networkCredential = new Networ

编写dotnet核心应用程序。我需要使用网络凭据登录,因为服务(恰好是prem服务器上的TFS)使用这些凭据进行身份验证。在我(和另一个团队成员)的windows计算机上,以下代码起作用:

Console.WriteLine("Type in your DOMAIN password:");
var pass = GetPassword(); //command line secure string magic from SO
var networkCredential = new NetworkCredential("USERNAME", pass, "DOMAINNAME");
string tfsDefaultCollection = "https://TFSURL/DefaultCollection";

string testUrl = $"{tfsDefaultCollection}/_apis/tfvc/changesets/1234/changes?api-version=2.2";

var httpClientHandler = new HttpClientHandler
{
    Credentials = networkCredential
};

var client = new HttpClient(httpClientHandler)
{
    BaseAddress = new Uri(testUrl)
};
httpClientHandler.PreAuthenticate = true;

var test = client.GetAsync(testUrl).Result;

Console.WriteLine(test);
但在我的mac电脑上它不工作。我得到了一份未经授权的401。两者都使用相同的硬接线连接。这在我的mac电脑上起作用:

curl --ntlm --user "DOMAINNAME\USERNAME" "https://TFSURL/DefaultCollection/_apis/tfvc/changesets/1234/changes?api-version=2.2"

我想这排除了连通性问题。我是否错过了在mac电脑上需要做的事情?有人能给我指一些文档或方法来解决这两个请求在最低级别上都在做什么,看看是否有区别吗?

好的,最后一些google foo帮我找到了。dotnetcoreforlinux/mac中有一个bug。此问题描述了修复程序:

这与您连接的主机有关,它同时使用Kerberos和NTLM身份验证方法

执行情况如下:

AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

Console.WriteLine("Type in your DOMAIN password:");
var pass = GetPassword(); //command line secure string magic from SO
var networkCredential = new NetworkCredential("USERNAME", pass, "DOMAINNAME");
string tfsDefaultCollection = "https://TFSURL/DefaultCollection";

string testUrl = $"{tfsDefaultCollection}/_apis/tfvc/changesets/1234/changes?api-version=2.2";

var myCache = new CredentialCache
{
    {
        new Uri(testUrl), "NTLM",
        networkCredential
    }
};

var httpClientHandler = new HttpClientHandler
{
    Credentials = myCache
};

var client = new HttpClient(httpClientHandler)
{
    BaseAddress = new Uri(testUrl)
};
httpClientHandler.PreAuthenticate = true;

var test = client.GetAsync(testUrl).Result;

Console.WriteLine(test);

感谢@dmcgill50让我进入了正确的谷歌搜索轨道。

你检查过这个问题了吗?它没有一个被接受的答案,但看起来与你的问题很接近:我认为关键的区别在于证书的问题——谢谢,我只是尝试了一下,没有成功。尽管我认为这也是我之前多次迭代中的一次。在我的windows机器上工作…您是否尝试过使用客户端访问TFS?