I have a for loop that loops with a listbox. For each item in the listbox I want to perform a httpwebrequest. My loop is doing the first item then occasionally just iterates down the list not doing the httpwebrequest for the other items. Im not sure if theres not enough time between requests or something.

Maybe you can help. I removed my postdata and sites I request to on purpose:

listBox4.SetSelected(i, true);
                listBox5.SetSelected(i, true);

                string[] details = { listBox4.SelectedItem.ToString(), listBox5.SelectedItem.ToString() };

                foreach (string element in details)

                    System.Net.ServicePointManager.Expect100Continue = false;

                    string postdata = "";

                    UTF8Encoding encoding1 = new UTF8Encoding();
                    byte[] bytedata = encoding1.GetBytes(postdata);

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");
                    request.Method = "POST";
                    request.KeepAlive = false;
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.Referer = "";
                    request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv: Gecko/20070725 Firefox/";
                    request.ContentLength = bytedata.Length;

                    Stream postreqstream2 = request.GetRequestStream();
                    postreqstream2.Write(bytedata, 0, bytedata.Length);
                    HttpWebResponse response = default(HttpWebResponse);

                    response = (HttpWebResponse)request.GetResponse();
                    StreamReader reader2 = new StreamReader(response.GetResponseStream());

                    string twitter = reader2.ReadToEnd();
                    richTextBox1.Text = twitter;
                    webBrowser1.DocumentText = (richTextBox1.Text);

                    toolStripStatusLabel1.Text = "Idle";
listBox6.Items.Add(listBox5.SelectedItem.ToString() + ":" + txtBoxImportPasswords.Text + "\r");


Recommended Answers

All 3 Replies

Thanks I will look at the link

Alright I saw it and came back with this code:

HttpWebRequest webRequest;

void StartWebRequest()
    webRequest.BeginGetResponse(new AsyncCallback(FinishWebRequest), null);

void FinishWebRequest(IAsyncResult result)

Where do I add it? In my httpwebrequest, above it? Also is the code copy/paste-able? Do I need to edit anything in my httpwebrequest? Also does my httpwebrequest need to be inside a method?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.