473,382 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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
Nov 18 '05 #1
4 7060
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Luis Faisco | last post by:
Hi, my problem may be trivial but I have been searching for an answer to this on the web without success. Hope you can help. This is the scenario: I am making a wizard composed of several...
3
by: q2005 | last post by:
Hi, all Is that possible I can do window.open("http://xserver1/app/typ/test/tesServer.php?aaa=111&bbb=222&ccc= 333","","") to simulate a POST ACTION with a form rather than a GET ACTION? Jack
10
by: JustSomeGuy | last post by:
I need to log into a web page automatically. The web page has a password text field and a login button. (A form?) How do I simulate that a user logged in and entered the password and pressed...
2
by: dast | last post by:
I want to simulate an input and post into a web page and than download the web page that is opened after the correct input! The web page exists of an user input form with userid and password, after...
2
by: _mario.lat | last post by:
I'd like to get text of a webpageB that I reach by putting a login and a password in a webpageA. I mean: I'd like to get text of a WebPageB with a php script. But before I can see WebPageB I...
2
by: Eli | last post by:
HI! I made some quiz using one HTML form (few question with few radio-button each like potential answers) that have one Submit button. I would like to simulate click on this button (e.g. named...
6
by: BarryX | last post by:
Hi, How do I simulate this from the server side: <form name="SearchForm" method="POST" id="SearchForm" action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2"> I have generally been posting data...
1
by: BarryX | last post by:
Hi, How do I simulate this from the server side: <form name="SearchForm" method="POST" id="SearchForm" action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2"> I have generally been posting data...
0
by: nospam | last post by:
Hello, I want to simulate posting to a form method with some data. I don't want to use query strings. I want to 'submit' to a php method with some form fields filled out on the server. So,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.