Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   How to simulate a form post? (http://www.velocityreviews.com/forums/t73301-how-to-simulate-a-form-post.html)

Al Cadalzo 02-17-2004 01:18 PM

How to simulate a form post?
 
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



George Ter-Saakov 02-17-2004 01:57 PM

Re: How to simulate a form post?
 
"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" <cadalzo@hotmail.com> wrote in message
news:Ovh3CiV9DHA.3648@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
>
>




Dino Chiesa [Microsoft] 02-17-2004 01:58 PM

Re: How to simulate a form post?
 
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" <cadalzo@hotmail.com> wrote in message
news:Ovh3CiV9DHA.3648@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
>
>




Al Cadalzo 02-17-2004 05:09 PM

Re: How to simulate a form post?
 
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" <nospam@hotmail.com> wrote in message
news:ulxRR3V9DHA.2432@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" <cadalzo@hotmail.com> wrote in message
> news:Ovh3CiV9DHA.3648@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
> >
> >

>
>




Al Cadalzo 02-17-2004 05:11 PM

Re: How to simulate a form post?
 
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]" <dinoch@online.microsoft.com> wrote in message
news:efC6p4V9DHA.2696@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" <cadalzo@hotmail.com> wrote in message
> news:Ovh3CiV9DHA.3648@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
> >
> >

>
>





All times are GMT. The time now is 09:00 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.