Reputation: 1085
I have this code:
using System.Net;
using System.Net.Http;
class Program
{
static void Main(string[] args)
{
NetworkCredential credential = new NetworkCredential("user", "password", "domain");
using (HttpClientHandler handler = new HttpClientHandler() { Credentials = credential })
{
using (HttpClient client = new HttpClient(handler))
{
string authUrl = "https://example.net";
var authresponse = client.GetAsync(authUrl).Result;
}
}
}
}
(url and credentials are anonymized)
In .net framework console I get response 200.
In .net core 1.1 I get response 401.
I guess it is difference in implementation between .net core and .net framework. Any ideas how to solve this? Or where to report this bug/feature?
Thanks
Upvotes: 1
Views: 2667
Reputation: 488
I believe you should be able to use a CredentialCache explicitly specifying that you're using NTML scheme. Also apparently this should not be necessary in more recent .netcore versions
https://github.com/dotnet/corefx/issues/9533
Upvotes: 0
Reputation: 1085
In the end I solved it like this:
NetworkCredential credential = new NetworkCredential("user", "password", "domain");
using (WinHttpHandler handler = new WinHttpHandler() { ServerCredentials = credential})
{
using (HttpClient client = new HttpClient(handler))
{
string authUrl = "https://example.net";
var authresponse = client.GetAsync(authUrl).Result;
}
}
Upvotes: 3