Query string is not everything, and this is not main part and not always used. You really need to use the class
System.Net.HttpWebRequest
, but your compile-time variable will be of the class
System.Net.WebRequest
as the run-time type is defined by URI passed as a parameter of it factory method.
Create
, see:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx[
^].
See the code sample in the second article referenced above, but this is for HTTP method 'get' (default), but you will need to use 'post'.
You can find a 'post' sample here:
http://www.jigar.net/howdoi/viewhtmlcontent106.aspx[
^]. Ignore that fact that this is ASP.NET sample — what's the difference.
Main thing you need to do is to find out what post string to write to the request string (again, see the sample above). It depends on the form data which is expected by the server part; and this is the data you will need to simulate in your request. Pay attention to the "name" attributes in your form. You will need to send those names and values by writing them in your request stream. Basically, the name/value pairs are written in the same format as the query string used in URL; look at the sample format string "
field1={0}&field2={1}
" in the code referenced above. In this example, the "name" attributes in the Web form's control are
field1
and
field2
and the values are defined by the input of the user of the Web form. You simulate this input using the post string like in the example shown above.
—SA