HttpClient.GetAsync with network credentials

I am currently using HttpWebRequest to get a website. I would like to use a wait pattern that is not specified for HttpWebRequests . I found the HttpClient class, which seems to be the new Http working class. I am using HttpClient.GetAsync(...) to request my web page. But I miss the opportunity to add ClientCredientials as HttpWebRequest.Credentials . Is there a way to provide HttpClient authentication HttpClient ?

+67
c # async-await
Apr 24 '12 at 6:23
source share
1 answer

You can pass an instance of the HttpClientHandler class with credentials to the HttpClient constructor :

 using (var handler = new HttpClientHandler { Credentials = ... }) using (var client = new HttpClient(handler)) { var result = await client.GetAsync(...); } 
+118
Apr 24 '12 at 6:26
source



All Articles