gpt4 book ai didi

c# - 如何用HttpClient替换WebClient?

转载 作者:行者123 更新时间:2023-12-02 03:43:09 25 4
gpt4 key购买 nike

我的 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

最佳答案

// Injecting HttpClient would be a better idea if possible
HttpClient client = new();
string page = await client.GetStringAsync("page URL here");

关于c# - 如何用HttpClient替换WebClient?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33020657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com