Skip to content

NTLM authentication HttpClient in Core 3.1 #35365

@Anhbta

Description

@Anhbta

I'm trying to use HttpClient to call rest api that requires NTLM authentication.
Below code works fine in .net core 2.2 but keep getting 401 with .net core 3.1

static void Main(string[] args)
{
    var client = Create("base-url");
    var response = client.GetAsync("api/v1.0/token").Result;

    HttpClient Create(string urlRoot)
    {
        var uri = new Uri(urlRoot);
        var handler = new HttpClientHandler() { PreAuthenticate = true, UseDefaultCredentials = true};
        var httpClient = new HttpClient(handler) { BaseAddress = uri  };
        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        return httpClient;
    }
}

This is running in windows 10.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions