【发布时间】:2021-01-15 21:00:34
【问题描述】:
如果可能的话,我需要帮助将此 WebClient 转换为 HttpClient 代码,如果可以的话,我会非常高兴。
我一直在寻找可以将其转换为我的东西/人,但遗憾的是我没有找到任何东西。
谢谢!
private void bunifuFlatButton9_Click(object sender, EventArgs e)
{
{
using (WebClient webClient = new WebClient())
{
webClient.Encoding = Encoding.UTF8;
webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(this.Complete);
webClient.DownloadDataAsync(new Uri("https://www.bing.com/search?q=site:pastebin.com+" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://www.bing.com/search?q=site:pastebin.com+" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://duckduckgo.com/?q=site%3Apastebin.com+" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://duckduckgo.com/?q=site%3Apastebin.com+" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://duckduckgo.com/?q=site%3Apastebin.com+" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://yandex.ru/search/?text=" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://yandex.ru/search/?text=" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://yandex.ru/search/?text=" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://yandex.ru/search/?text=" + this.textBox1.Text));
webClient.DownloadDataAsync(new Uri("https://yandex.ru/search/?text=" + this.textBox1.Text));
}
}
}
private void Complete(object sender, DownloadDataCompletedEventArgs e)
{
MatchCollection matchCollection = Regex.Matches(new UTF8Encoding().GetString(e.Result), "(https:\\/\\/pastebin.com\\/\\w+)");
int num = checked(matchCollection.Count - 1);
int i = 0;
while (i <= num)
{
using (WebClient webClient = new WebClient())
{
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(this.Complete2);
webClient.DownloadStringAsync(new Uri(matchCollection[i].Value));
}
checked { ++i; }
}
}
【问题讨论】:
-
你有什么问题。这是一个“问答”网站,而不是“我们为您编写代码”网站
-
你使用了哪个框架? Netcore 还是 NetFramwork?哪个版本?
-
@Amir 我正在使用 NetFramework。
-
@SOLO 如果你实现了请标记为正确答案。
标签: c# httpclient webclient