Posting data using HttpWebRequest

  • Thread starter Thread starter Beenish Sahar Khan
  • Start date Start date
B

Beenish Sahar Khan

I am using the following piece of code to post some data to a web form,

req.Method = "POST";

req.ContentType = "application/x-www-form-urlencoded";


req.ContentLength =formcontents.Length;

sendStream = req.GetRequestStream();

sendStream.Write(formcontents, 0, formcontents.Length);

sendStream.Close();

res = (HttpWebResponse)req.GetResponse();

on last line its continously givng me the following error..

"The remote server returned an error: (500) Internal Server Error."

but the server is my own application, which is working fine, when instead of
giving form contents length i give it hardcoded value it runs fine uptil 7
but after that start giving this error formcontents is a byte[].

Any kind of help will be appreciated.

regards,

Beenish.
 
Beenish said:
I am using the following piece of code to post some data to a web
form,

req.Method = "POST";

req.ContentType = "application/x-www-form-urlencoded";


req.ContentLength =formcontents.Length;

sendStream = req.GetRequestStream();

sendStream.Write(formcontents, 0, formcontents.Length);

sendStream.Close();

res = (HttpWebResponse)req.GetResponse();

on last line its continously givng me the following error..

"The remote server returned an error: (500) Internal Server Error."

but the server is my own application, which is working fine, when
instead of giving form contents length i give it hardcoded value it
runs fine uptil 7 but after that start giving this error formcontents
is a byte[].

Debug your server-side code. It's probably expecting some HTTP header
like User-Agent, which your code does not transmit.

Cheers,
 
Back
Top