我正在尝试使用HttpClient来访问需要NTLM身份验证的REST服务。但是我一直在获得401 Unauthorized。 我的代码看起来像这样
private static void Main()
{
var uri = new Uri("http://localhost:15001");
var credentialsCache = new CredentialCache { { uri, "NTLM", CredentialCache.DefaultNetworkCredentials } };
var handler = new HttpClientHandler { Credentials = credentialsCache };
var httpClient = new HttpClient(handler) { BaseAddress = uri, Timeout = new TimeSpan(0, 0, 10) };
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = httpClient.GetAsync("api/MyMethod").Result;
}
我的目标框架是netcoreapp2.0。如果我改为net461,它将起作用。不确定我做错了什么?