473,804 Members | 3,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submit a HTML Form programmaticall y

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 60919
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
GetRequestStrea m, and write to the stream the content of the forms data.

First, you need to set the ContentType property to
"applicatio n/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
GetRequestStrea m the values in the following manner:

name1=value1&na me2=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************* *@exisconsultin g.com

"Darran" <Da***********@ hotmail.com> wrote in message
news:4f******** *************** **@posting.goog le.com...
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************* *@exisconsultin g.com

"Darran" <Da***********@ hotmail.com> wrote in message
news:4f******** *************** **@posting.goog le.com...
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 New Member
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 New Member
Uhm.. Nobody knows? :(
Jun 12 '06 #5
MyWay
3 New Member
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
18361
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 want to detect when the frame has been loaded with the result of the form submit. Of course I have tried some event handlers like onload, onactivate, onreadystatechange, but they do not work in this example. They only seem to work, when the "SRC"...
0
1828
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 to log onto Horde webmail the users have to fill in 5 fields. I wanted to simplify things for them so they only had to click a button once logged into the aps.net site. At the moment i do this by recreating the form on my webform making all the...
5
2108
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 type="submit" name="submit1"> <input type="submit" name="submit1" runat="server"> Please advise! Thanks!!
12
3448
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 this? Here is HTML code from webform.. Thanks, Sinisa
8
5081
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 to asp.net vb code? !--<FORM ACTION="/test/test.php" METHOD=POST>--> <form action="https://multipay.net/transaction/mpmain.php" method="post"> ....
5
17715
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 type=password maxlength="8" name="password" value="`pss`"> where usr and pss are sent from the previous form.
5
7537
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 radio buttons (for each row of the table) and a main submit button. On clicking submit..i want to loop through the table..pick up the first <TDbeing the user ID and the value of the radio button clicked (currently I have my radio button ID set...
1
10828
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 have defined the relavant function method in the code for details) The issue is that when Icall targetForm._submit() method from the newSubmit() function the page I get an 'Object doesn't support this property or method' error I am using IE...
4
5515
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 call a form's submit. I've found how to post programatically, but I need to use the form's target attribute so that the response goes into another frame, and I can't figure out how to do that programatically.
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9160
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.