Thursday, December 15, 2016

Setting Credentials for HttpClient

I'm starting to get into .NET Core and I'm writing a client that accesses a REST api. The api in question is a SharePoint api so, naturally, it requires credentials. I finally figured out how to set the credentials for the HttpClient using this code:

        CredentialCache.DefaultNetworkCredentials.Domain = "sp";
        CredentialCache.DefaultNetworkCredentials.UserName = "administrator";
        CredentialCache.DefaultNetworkCredentials.Password = "P@ssw0rd";

If anyone has a better way, let me know.

P.S. Don't try to use my super secret password to hack my bank account, it probably won't work :)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.