HTTP POST

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to do an http post to a url and include the name/value pairs for the
fields in the form. The WebClient class lets me do this with the
UploadValues method but I need to use a timeout as well, which is contained
in the WebRequest and WebResponse classes. Does anyone know how to get the
HTML from a post with fields while, at the same time, limiting the time
you'll allow for it to complete?
 
to rewrite upoload values is trival, so that you can use WebRequest

air code:

void UploadValues(WebRequest wr, NameValueCollection values)
{
wr.ContentType = "application/x-www-form-urlencoded";
string sep = "";
for (int i=0; i < values.Count; ++i)
{
string s = string.Format("{0}{1}={2}",
sep,
HttpUtility.UrlEncode(values.GetKey(i)),
HttpUtility.UrlEncode(values.Get(i)));
sep = "&";
byte[] buffer = Encoding.ACII.GetBytes(s);
wr.GetRequestStream().Write(buffer,0,buffer.Length);
}
}

-- bruce (sqlwork.com)
 
Back
Top