tags:

views:

144

answers:

2

Hi all,

I've seen a tons of sample to how to programmatically submit a form (in .NET) but none of them has the specific requirements I need.

The case I'm working on has a query string (http://.../index=?p=update), some hidden fields and a upload file.

Does anyone has managed to submit this kind of form with a webrequest?

Thanks a lot in advance, Fabian

A: 

Examine the form method. If it's GET, then you'll need to send all data in the URL. This means you simply append &field1=value1&field2=value2... etc. (field1, field2 being the id or name of the field).

It is more likely POST. You'll have to set the request method to post (see here). However, this does not mention the interesting part: what should I write into the request stream? This is (surprisingly) the same you would apply to the URL when GET method was used:

string requestString = String.Format("field1={0}&field2={1}", value1, value2);

And write this string into the request stream. That is all, this should work. (you can also mix the two, e.g. can use the p=update paramter in the URL, while POSTing data)

Tamás Szelei