这只发送了两个请求

时间:2013-08-28 04:39:46

标签: c#

private async void button2_Click(object sender, EventArgs e)
    {
        {
            var cookie = webBrowser1.Document.Cookie;
            foreach (string s in listBox1.Items)
            {
                var data = "postdata" + s;
                var req = WebRequest.Create("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请求。它正在这样做,但即使我有数百个项目,它只运行两个,然后停止。我没有收到任何错误,所以我不明白什么是错的。我已经确定只通过在其中放置一个消息框来运行两次。

0 个答案:

没有答案