Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how do i make a program which can fill up other webpages and give me the result page?. like submitting a email account form and receiving the result form and save the text/page. using c#/asp.net?
Posted

1 solution

You don't need to "fill up" anything. (What it could be? :-))

Let's see. When you act as a user of a browser and fill up controls of a Web form, and then click "submit", the browser uses the data you input to create an HTTP request and sends it to the server. This request carries the parameters you input using key-value pairs; the key is the same as the attribute name of each input control under the form and the value is its string value.

So, all you need it to do the same thing without a browser. You should know what is the structure of the HTTP request in case of each form and send the same very request, obtain the HTTP response and then the content is this response will be the content of the "result page" you are looking for.

To do so, you need to use the class System.Net.HttpWebRequest:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].

Here is how you get the HTTP response: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx[^].

Please see also my past answers:
get specific data from web page[^],
How to get the data from another site[^].

Now, to learn the structure of the HTTP request for the form? Apparently, by looking at the HTML source code for the forms you want to mimic, which is easily done through browser's "View Source Code" menu item (or something like that). Pay attention for controls' name attributes mentioned above.

The format of the key-value pairs is shown in many places. For example, see code sample (please see the first answer): http://stackoverflow.com/questions/10263082/how-to-pass-post-parameters-to-asp-net-web-request[^].

It would be good the debug the technique when be writing your own small ASP.NET application (which you can debug on local host using the debug HTTP server included in Visual Studio), to see how the form and its data is translated into an HTTP request, which you can test on the server side. For your working code this is not needed, I mean just the study stage, which can save you considerable time.

—SA
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900