private async void button1_Click(object sender, EventArgs e)
{
var cookie = webBrowser1.Document.Cookie;
await
Task.WhenAll(
listBox1
.Items
.Cast<string>()
.Select(async s =>
{
var data = "action=relationship&user_id=" + s + "&relation=follow";
var req = WebRequest.Create("http://example.com") as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
req.Headers["cookie"] = cookie;
using (var sw = new StreamWriter(await req.GetRequestStreamAsync(), Encoding.ASCII))
{
sw.Write(data);
sw.Close();
}
}));
listBox1.Items.Clear();
}
我已经尝试过一百万次,每次运行两次。当它运行这两次时,它会做它应该做的事情。
它应该做的是从列表框中获取项目,并将每个项目用作 POST 请求的一部分。然后当它完成时,它会清除列表框。
有人可以解释什么是错的吗?