Avoid using user name and password for HttpClientHandler

112 Views Asked by At

I am using the following code to prepare a handler for HttpClient:

var uri = new Uri("URL");
 var credentialsCache = new CredentialCache();
 credentialsCache.Add(uri, "NTLM", new NetworkCredential("username", "password"));
 var handler = new HttpClientHandler() { Credentials = credentialsCache, PreAuthenticate = true };
 handler.ClientCertificateOptions = ClientCertificateOption.Manual;
 handler.ServerCertificateCustomValidationCallback =
 (httpRequestMessage, cert, cetChain, policyErrors) =>
 {
            return true;
 };
 ....
 new HttpClient(handler);

Is it possible to avoid using real username and password?

Thanks

0

There are 0 best solutions below