HttpWebRequest Timout Error Problem

M

Matt

I am having trouble with the HttpWebRequest.GetRequestStream method.

I am posting data to my web server running NT4 iis4 using a loop. So
every time the loop executes I want it to post data to my web page.
It work the first 2 times the loop iterates, but on the third time
around it gives me a timout error.

The line it gives me an error on is:
--Stream newStream = myRequest.GetRequestStream();--

Could someone please point me in the right direction.

Many thanks!


Form Code:
private void button1_Click(object sender, System.EventArgs e)
{
int x;
x=0;
while(x < 1)
{
this.textBox1.Text = "Sleeping";
Application.DoEvents();
Thread.Sleep(3000);

HRATS_Functions X = new HRATS_Functions();

try
{
X.PostData();
X.Dispose();
//this.textBox2.Text = X.myResponse.ToString();
}
catch (Exception a)
{
this.textBox1.Text = "Exception: " + a.ToString();
break;
}

this.textBox1.Text = "Awake";
Application.DoEvents();
Thread.Sleep(3000);
}
}


Class Code:
public HttpWebRequest myRequest =
(HttpWebRequest)Request.Create("http://lab/collectdata.asp");
public ASCIIEncoding encoding = new ASCIIEncoding();
public string myResponse;

public void PostData()
{
// Initialize the WebRequest parameters
string postData = "First_Name=Matt";
byte[] byte1 = encoding.GetBytes(postData);

//Set Request Properties
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = postData.Length;
myRequest.Timeout = 5000;

//send the request
Stream newStream = myRequest.GetRequestStream();
newStream.Write(byte1,0,byte1.Length);
newStream.Flush();
newStream.Close();
}
 
V

Victor Bazarov

Matt said:
I am having trouble with the HttpWebRequest.GetRequestStream method.

I am posting data to my web server running NT4 iis4 using a loop. So
every time the loop executes I want it to post data to my web page.
It work the first 2 times the loop iterates, but on the third time
around it gives me a timout error.
[...]

This has nothing to do with the language. Please post to a forum
where 'HttpWebRequest' is on topic, I think you should find more help
in comp.os.ms-windows.programmer.win32.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top