Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to simulate a form post?

Reply
Thread Tools

How to simulate a form post?

 
 
Al Cadalzo
Guest
Posts: n/a
 
      02-17-2004
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


 
Reply With Quote
 
 
 
 
George Ter-Saakov
Guest
Posts: n/a
 
      02-17-2004
"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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Dino Chiesa [Microsoft]
Guest
Posts: n/a
 
      02-17-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Al Cadalzo
Guest
Posts: n/a
 
      02-17-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Al Cadalzo
Guest
Posts: n/a
 
      02-17-2004
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to simulate POST Form on server? nospam ASP .Net 1 10-13-2007 03:01 AM
Simulate form post from Server Side BarryX ASP General 9 10-02-2007 07:04 AM
Simulate Form Post on Server Side BarryX ASP .Net 1 09-26-2007 10:48 AM
error trying to simulate NCO form quartus in matlab Juan Carlos Allica VHDL 0 07-15-2005 05:29 PM
simulate virtual directory - I need it urgently Amir Eshterayeh ASP .Net 1 02-05-2004 01:11 PM



Advertisments