1

Why can't I add authentication details after adding a DelegatingHandler?

Prior to adding the DelegatingHandler, I was able to instantiate the HttpClient like so:

var client = new HttpClient{Credentials = ..., BaseAddress = ...};

After having added a DelegatingHandler, I am unable to add Credentials and BaseAddress:

var client = new HttpClient(new RetryHandler(new HttpClientHandler()));
client.BaseAddress = // does not exist!
client.Credentials = // does not exist!

How do we add credentials and a baseaddress to this client?

1 Answer 1

2

This is how you can pass credentials into your handler:

var clientHandler = new HttpClientHandler()
{
    Credentials = ...
};

var retryHandler = new RetryHandler(clientHandler);

var client = new HttpClient(retryHandler )
{
    BaseAddress = ...
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.