tags:

views:

49

answers:

2

This is a quick and dirty app that only needs to work for a short period. I'm not a developer so please don't hammer me. The following code in asp works fine (secret info replaced with example.com and abc 123).

I know the below is very bad practice, but this is just for demonstration purpose:

<form method="post" action="https://example.com/asppage.aspx" id="frm_main">
<input type="hidden" name="STATE" id="STATE" value="ABC" />
<input type="hidden" name="VALIDATION" id="VALIDATION" value="123/>
<input type="submit" name="refresh_progress" value="Check Status" id="refresh_progress" /></form>

However, the same code in my c# post doesn't work:

string PostData = "STATE=ABC&amp;VALIDATION=123";
webBrowser1.Navigate("https://example.com/asppage.aspx", "_blank", Encoding.Default.GetBytes(PostData), "Content-Type: application/x-www-form-urlencoded\n\r");

When the new browser window pops up, its the default asppage.aspx form with no data posted to it.

Any ideas what I'm doing wrong?

A: 

Your POST format is completely wrong.

See the specification.

SLaks
I corrected some typos, that link explains some post info, but I'm not a developer by trade, so it's a bit confusing. Could you elaborate please.
shaiss
+1  A: 

You're giving the webBrowser the html of the form, the POST data is a serialised format of the names and values of the form fields which is what you need to put in your Navigate method.

The postdata needs to be in the format:

inputname1=value1&inputname2=value2&inputname3=value3

You will also need to uri encode the string and include Content-Type: application/x-www-form-urlencoded as the fourth parameter in the method call.

Chao
Thanks for the direction, could you elaborate more please. I tried `string PostData="QUJD";` which is ABC encoded Base64. Is that the correct "serialized" data?
shaiss
See edited answer
Chao
I corrected the post format above per your suggestion, however, still no luck. Looks like I'm getting closer, but just missing something small.
shaiss
Chao