GetResponse() & POST timeouts

G

Guest

I am trying to get the following code to work :

HttpWebRequest request1 = (HttpWebRequest)
WebRequest.Create(@"http://localhost/TacUssd/8.tac");
request1.Method = "POST";
request1.Credentials = System.Net.CredentialCache.DefaultCredentials;
request1.ContentType = "application/x-www-form-urlencoded";
//Stream stream = request1.GetRequestStream();
//Stream sr = File.Open(@"D:\My Documents\Visual Studio
Projects\ussd\test.xml", FileMode.Open);
//byte[] bits = new byte[sr.Length];
//sr.Read(bits, 0, bits.Length);
//stream.Write(bits, 0, bits.Length);

//request1.Timeout = 1000;
HttpWebResponse response1 = (HttpWebResponse) request1.GetResponse();

Stream stream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(stream1, Encoding.UTF8);
string text1 = reader1.ReadToEnd();
stream1.Close();
response1.Close();

but I keep get timeouts.

does anyone have any suggestions on this.
I can get it to work fine with "GET", but not with POST.

Thanks in advance
 
J

Joerg Jooss

Garnet2 said:
I am trying to get the following code to work :

HttpWebRequest request1 = (HttpWebRequest)
WebRequest.Create(@"http://localhost/TacUssd/8.tac");
request1.Method = "POST";
request1.Credentials = System.Net.CredentialCache.DefaultCredentials;
request1.ContentType = "application/x-www-form-urlencoded";
//Stream stream = request1.GetRequestStream();
//Stream sr = File.Open(@"D:\My Documents\Visual Studio
Projects\ussd\test.xml", FileMode.Open);
//byte[] bits = new byte[sr.Length];
//sr.Read(bits, 0, bits.Length);
//stream.Write(bits, 0, bits.Length);

//request1.Timeout = 1000;
HttpWebResponse response1 = (HttpWebResponse) request1.GetResponse();

Stream stream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(stream1, Encoding.UTF8);
string text1 = reader1.ReadToEnd();
stream1.Close();
response1.Close();

but I keep get timeouts.

does anyone have any suggestions on this.
I can get it to work fine with "GET", but not with POST.

Of course not. This code doesn't write anything to the request stream, thus
never sending a HTTP body. Remove the comments...

Cheers,
 
G

Guest

I had tried that with the same error.


Joerg Jooss said:
Garnet2 said:
I am trying to get the following code to work :

HttpWebRequest request1 = (HttpWebRequest)
WebRequest.Create(@"http://localhost/TacUssd/8.tac");
request1.Method = "POST";
request1.Credentials = System.Net.CredentialCache.DefaultCredentials;
request1.ContentType = "application/x-www-form-urlencoded";
//Stream stream = request1.GetRequestStream();
//Stream sr = File.Open(@"D:\My Documents\Visual Studio
Projects\ussd\test.xml", FileMode.Open);
//byte[] bits = new byte[sr.Length];
//sr.Read(bits, 0, bits.Length);
//stream.Write(bits, 0, bits.Length);

//request1.Timeout = 1000;
HttpWebResponse response1 = (HttpWebResponse) request1.GetResponse();

Stream stream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(stream1, Encoding.UTF8);
string text1 = reader1.ReadToEnd();
stream1.Close();
response1.Close();

but I keep get timeouts.

does anyone have any suggestions on this.
I can get it to work fine with "GET", but not with POST.

Of course not. This code doesn't write anything to the request stream, thus
never sending a HTTP body. Remove the comments...

Cheers,
 
J

Joerg Jooss

Garnet2 said:
I had tried that with the same error.
HttpWebRequest request1 = (HttpWebRequest)
WebRequest.Create(@"http://localhost/TacUssd/8.tac");
request1.Method = "POST";
request1.Credentials = System.Net.CredentialCache.DefaultCredentials;
request1.ContentType = "application/x-www-form-urlencoded";
//Stream stream = request1.GetRequestStream();
//Stream sr = File.Open(@"D:\My Documents\Visual Studio
Projects\ussd\test.xml", FileMode.Open);
//byte[] bits = new byte[sr.Length];
//sr.Read(bits, 0, bits.Length);
//stream.Write(bits, 0, bits.Length);

You forgot to close the request stream.

Cheers,
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top