473,405 Members | 2,445 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,405 software developers and data experts.

Submit a HTML Form programmatically

Hi

I want to be able to retrieve the data from a given URL, fill in the
necessary form fields and submit the form back to the server, all from
within a Windows Application. I can retrieve the HTML from the page,
using the HttpWebRequest class but that is where I have become stuck.
These are the remaining items I would like to be able to do

1 Fill in the necessary fields on the form.
2 Submit the data back to the server
3 Retrieve the response from the server and start the loop again.

Any ideas?
Thanks

Darran
Nov 13 '05 #1
5 60812
Darran,

You will use the HttpWebRequest class just as you did before. However,
this time, you need to set the Method property to "POST", which will
indicate that you are posting data. Also, you will have to call
GetRequestStream, and write to the stream the content of the forms data.

First, you need to set the ContentType property to
"application/x-www-form-urlencoded".

Then, you have to find the ids of the controls that are going to send
information. You will have to then write to the Stream returned by
GetRequestStream the values in the following manner:

name1=value1&name2=value2

You have to make sure that the values are encoded correctly, as certain
characters are not allowed.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Darran" <Da***********@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi

I want to be able to retrieve the data from a given URL, fill in the
necessary form fields and submit the form back to the server, all from
within a Windows Application. I can retrieve the HTML from the page,
using the HttpWebRequest class but that is where I have become stuck.
These are the remaining items I would like to be able to do

1 Fill in the necessary fields on the form.
2 Submit the data back to the server
3 Retrieve the response from the server and start the loop again.

Any ideas?
Thanks

Darran

Nov 13 '05 #2
Darran,

Or, you can just use the UploadValues method on the WebClient class.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Darran" <Da***********@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi

I want to be able to retrieve the data from a given URL, fill in the
necessary form fields and submit the form back to the server, all from
within a Windows Application. I can retrieve the HTML from the page,
using the HttpWebRequest class but that is where I have become stuck.
These are the remaining items I would like to be able to do

1 Fill in the necessary fields on the form.
2 Submit the data back to the server
3 Retrieve the response from the server and start the loop again.

Any ideas?
Thanks

Darran

Nov 13 '05 #3
MyWay
3
I have to do a similar thing: fill 2 textbox with user and password, can you explain how to do it?
Jun 12 '06 #4
MyWay
3
Uhm.. Nobody knows? :(
Jun 12 '06 #5
MyWay
3
Expand|Select|Wrap|Line Numbers
  1.                         ASCIIEncoding encoding = new ASCIIEncoding();
  2.                         string postData = "username=" + strUser + "&password=" + strPass + "&login_button.x=0&login_button.y=0";
  3.                         byte[] data = encoding.GetBytes(postData);
  4.                         // Prepare web request...
  5.                         HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("urlofthesite");
  6.                         myRequest.Method = "POST";
  7.                         myRequest.ContentType = "text/html";
  8.                         myRequest.ContentLength = data.Length;
  9.                         Stream newStream = myRequest.GetRequestStream();
  10.                         // Send the data.
  11.                         newStream.Write(data, 0, data.Length);
  12.                         newStream.Close();
  13.  
I find out this code, but how can i check if i'm logged in succesfully or not?
Jun 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Halldór Ísak Gylfason | last post by:
In my application I have an iframe that is empty (and not visible) initially, however when a user presses a button a form is programmatically submitted and the target is set to the IFrame. I...
0
by: spamfurnace | last post by:
Hi there on this rainy old day, I have some users logging into an asp.net website. The server the site sits on allows users to webmail through a common service/component called Horde. In order...
5
by: Matt | last post by:
I want to know what is the purpose of runat="server" attribute?? For example, for a submit button, it just submit the form data to the server, whats the differences between <input...
12
by: TheOne | last post by:
In Asp.net web form under form tag there is action field that I am point to some other page, and not to same web form. When I run this page it is always pointing to itself. How do I get around...
8
by: Gert | last post by:
Hi, I have a form (server side) because of the filling of variables through the application. But now I need to post it to an url on submit. My .HTML form looks like this, but how to translate it...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
5
by: g | last post by:
Hi Guys.. i know this might sound really really simple, but I'm kinda stuck..I have this form..which has a table (created from stored procedure values)..once the table is populated..i have some...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
4
by: j1dopeman | last post by:
Hi, I'd like to use a button to save and then submit a form. I can set the onlick of the button to mahButton_click or submit, but I can't figure out how to do both. It looks like c# can't...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.