HttpClient.GetAsync with network credentials

前端 未结 1 1120
清歌不尽
清歌不尽 2020-11-30 22:20

I\'m currently using HttpWebRequest to get a website. I\'d like to use the await pattern, which is not given for HttpWebRequests. I found the class

相关标签:
1条回答
  • 2020-11-30 22:46

    You can pass an instance of the HttpClientHandler Class with the credentials to the HttpClient Constructor:

    using (var handler = new HttpClientHandler { Credentials = ... })
    using (var client = new HttpClient(handler))
    {
        var result = await client.GetAsync(...);
    }
    
    0 讨论(0)
提交回复
热议问题