如何用 HttpClient 替换 WebClient?

问题描述 投票:0回答:1

我的 asp.net mvc web 应用程序中有以下 WebClient:

using (WebClient wc = new WebClient()) // call the Third Party API to get the account id 
{
     string url = currentURL + "resources/" + ResourceID + "/accounts?AUTHTOKEN=" + pmtoken;
     var json = await wc.DownloadStringTaskAsync(url);
 }

所以任何人都可以建议我如何将它从

WebClient
更改为
HttpClient

c# .net webclient webrequest
1个回答
40
投票
HttpClient client = new HttpClient();   // actually only one object should be created by Application
string page = await client.GetStringAsync("page URL here");
© www.soinside.com 2019 - 2024. All rights reserved.