0
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 请求。它正在这样做,但即使我有数百个项目,它也只运行两个,然后停止。我没有收到任何错误,所以我不明白出了什么问题。我通过在其中放置一个消息框来确保它只运行两次。

4

0 回答 0