By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

How to simulate a form post?

P: n/a
I'm trying to simulate a form post (i.e. Method="POST").

The FORM POST I'm trying to simulate is similar to this:

<FORM NAME=SearchForm METHOD=POST ACTION=Search>
<SELECT name="criteriaA" >
<OPTION VALUE=1>AAAAAAAAAAA</OPTION>
<OPTION VALUE=2>BBBBBBBBBBBB</OPTION>
</SELECT>
....
</FORM>

Here is my code:

Uri httpSite = new Uri(url);

WebRequest wreq = WebRequest.Create(httpSite);

wreq.ContentType = "application/x-www-form-urlencoded";
wreq.Method = "POST";
string formvars = string.Empty;
formvars = "criteriaA=1&criteriaB=2";

Byte[] byteArray = Encoding.UTF8.GetBytes(formvars);

wreq.ContentLength = byteArray.Length;
Stream reqStream = wreq.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);

reqStream.Close();
<<

Am I specifying the form variables correctly?

The FORM also has an ACTION=Search
How do I pass the ACTION=Search in my WebRequest?

I'm getting a response back with html of the page I'm requesting but it does
not have any search results.
The area of the page where the search results would appear is blank.

Any help or hints anyone can provide are appreciated.

Thanks,
Al
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Action" is actually the page where you submit the form.
So when you clicking submit button browser sents the POST request to the
page specified in "Action"

So in your case you must use
WebRequest wreq = WebRequest.Create(http://www.mysite.com/Search);

George.

"Al Cadalzo" <ca*****@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
I'm trying to simulate a form post (i.e. Method="POST").

The FORM POST I'm trying to simulate is similar to this:

<FORM NAME=SearchForm METHOD=POST ACTION=Search>
<SELECT name="criteriaA" >
<OPTION VALUE=1>AAAAAAAAAAA</OPTION>
<OPTION VALUE=2>BBBBBBBBBBBB</OPTION>
</SELECT>
...
</FORM>

Here is my code:
Uri httpSite = new Uri(url);

WebRequest wreq = WebRequest.Create(httpSite);

wreq.ContentType = "application/x-www-form-urlencoded";
wreq.Method = "POST";
string formvars = string.Empty;
formvars = "criteriaA=1&criteriaB=2";

Byte[] byteArray = Encoding.UTF8.GetBytes(formvars);

wreq.ContentLength = byteArray.Length;
Stream reqStream = wreq.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);

reqStream.Close();
<<

Am I specifying the form variables correctly?

The FORM also has an ACTION=Search
How do I pass the ACTION=Search in my WebRequest?

I'm getting a response back with html of the page I'm requesting but it

does not have any search results.
The area of the page where the search results would appear is blank.

Any help or hints anyone can provide are appreciated.

Thanks,
Al

Nov 18 '05 #2

P: n/a
The form action is the URL to which the form data should be submitted.

So your url should be "Search", eg

"http://something.org/Search"

(whatever the releative URL "Search" resolves to.)
"Al Cadalzo" <ca*****@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
I'm trying to simulate a form post (i.e. Method="POST").

The FORM POST I'm trying to simulate is similar to this:

<FORM NAME=SearchForm METHOD=POST ACTION=Search>
<SELECT name="criteriaA" >
<OPTION VALUE=1>AAAAAAAAAAA</OPTION>
<OPTION VALUE=2>BBBBBBBBBBBB</OPTION>
</SELECT>
...
</FORM>

Here is my code:
Uri httpSite = new Uri(url);

WebRequest wreq = WebRequest.Create(httpSite);

wreq.ContentType = "application/x-www-form-urlencoded";
wreq.Method = "POST";
string formvars = string.Empty;
formvars = "criteriaA=1&criteriaB=2";

Byte[] byteArray = Encoding.UTF8.GetBytes(formvars);

wreq.ContentLength = byteArray.Length;
Stream reqStream = wreq.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);

reqStream.Close();
<<

Am I specifying the form variables correctly?

The FORM also has an ACTION=Search
How do I pass the ACTION=Search in my WebRequest?

I'm getting a response back with html of the page I'm requesting but it

does not have any search results.
The area of the page where the search results would appear is blank.

Any help or hints anyone can provide are appreciated.

Thanks,
Al

Nov 18 '05 #3

P: n/a
George,
Thanks. I added that to the URL, but I'm still getting a blank section of
the response where the results would appear.
I can see most of the page except where the results would appear. I must be
missing one or more of the required form parameters.

Thanks,
Al

"George Ter-Saakov" <no****@hotmail.com> wrote in message
news:ul**************@TK2MSFTNGP09.phx.gbl...
"Action" is actually the page where you submit the form.
So when you clicking submit button browser sents the POST request to the
page specified in "Action"

So in your case you must use
WebRequest wreq = WebRequest.Create(http://www.mysite.com/Search);

George.

"Al Cadalzo" <ca*****@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
I'm trying to simulate a form post (i.e. Method="POST").

The FORM POST I'm trying to simulate is similar to this:

<FORM NAME=SearchForm METHOD=POST ACTION=Search>
<SELECT name="criteriaA" >
<OPTION VALUE=1>AAAAAAAAAAA</OPTION>
<OPTION VALUE=2>BBBBBBBBBBBB</OPTION>
</SELECT>
...
</FORM>

Here is my code:
>

Uri httpSite = new Uri(url);

WebRequest wreq = WebRequest.Create(httpSite);

wreq.ContentType = "application/x-www-form-urlencoded";
wreq.Method = "POST";
string formvars = string.Empty;
formvars = "criteriaA=1&criteriaB=2";

Byte[] byteArray = Encoding.UTF8.GetBytes(formvars);

wreq.ContentLength = byteArray.Length;
Stream reqStream = wreq.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);

reqStream.Close();
<<

Am I specifying the form variables correctly?

The FORM also has an ACTION=Search
How do I pass the ACTION=Search in my WebRequest?

I'm getting a response back with html of the page I'm requesting but it

does
not have any search results.
The area of the page where the search results would appear is blank.

Any help or hints anyone can provide are appreciated.

Thanks,
Al


Nov 18 '05 #4

P: n/a
Dino,

Thanks for your help. Still not getting the expected page results. Maybe
I'm missing a form variable. I'm going to try using WebClient.UploadValues.

Thanks,
Al
"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in message
news:ef**************@TK2MSFTNGP10.phx.gbl...
The form action is the URL to which the form data should be submitted.

So your url should be "Search", eg

"http://something.org/Search"

(whatever the releative URL "Search" resolves to.)
"Al Cadalzo" <ca*****@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP11.phx.gbl...
I'm trying to simulate a form post (i.e. Method="POST").

The FORM POST I'm trying to simulate is similar to this:

<FORM NAME=SearchForm METHOD=POST ACTION=Search>
<SELECT name="criteriaA" >
<OPTION VALUE=1>AAAAAAAAAAA</OPTION>
<OPTION VALUE=2>BBBBBBBBBBBB</OPTION>
</SELECT>
...
</FORM>

Here is my code:
>

Uri httpSite = new Uri(url);

WebRequest wreq = WebRequest.Create(httpSite);

wreq.ContentType = "application/x-www-form-urlencoded";
wreq.Method = "POST";
string formvars = string.Empty;
formvars = "criteriaA=1&criteriaB=2";

Byte[] byteArray = Encoding.UTF8.GetBytes(formvars);

wreq.ContentLength = byteArray.Length;
Stream reqStream = wreq.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);

reqStream.Close();
<<

Am I specifying the form variables correctly?

The FORM also has an ACTION=Search
How do I pass the ACTION=Search in my WebRequest?

I'm getting a response back with html of the page I'm requesting but it

does
not have any search results.
The area of the page where the search results would appear is blank.

Any help or hints anyone can provide are appreciated.

Thanks,
Al


Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.