473,322 Members | 1,526 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,322 software developers and data experts.

Post Forms Programmatically

Hello,

I would like to know how to post form data programmatically. The idea is
to get the intranet web page, programmatically entre the username and
password in a login form, post it and be redirected to the logged in
page. So far I have found the code to post data in a form, but I am not
sure if this is the correct way to do it.

Thank you in advance

string url = "http://intranet/app";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string proxy = null;

//string data = String.Format("USER={0}&PASSWORD={1}", "user",
"password");
byte[] buffer = Encoding.UTF8.GetBytes(data);

req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
req.Proxy = new WebProxy(proxy, true); // ignore for local
addresses
req.CookieContainer = new CookieContainer();
Stream reqst = req.GetRequestStream(); // add form data to request
stream
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
reqst.Close();

*** Sent via Developersdex http://www.developersdex.com ***
Aug 19 '08 #1
2 2423
David wrote:
I would like to know how to post form data programmatically. The idea is
to get the intranet web page, programmatically entre the username and
password in a login form, post it and be redirected to the logged in
page. So far I have found the code to post data in a form, but I am not
sure if this is the correct way to do it.
string url = "http://intranet/app";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string proxy = null;

//string data = String.Format("USER={0}&PASSWORD={1}", "user",
"password");
byte[] buffer = Encoding.UTF8.GetBytes(data);

req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
req.Proxy = new WebProxy(proxy, true); // ignore for local
addresses
req.CookieContainer = new CookieContainer();
Stream reqst = req.GetRequestStream(); // add form data to request
stream
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
reqst.Close();
The looks OK when quickly reading it.

What is the problem ?

Arne
Aug 19 '08 #2
Hi Arne,

The problem is that when I post the data to the form, I need to open
another URL that is password protected programmatically (hence sending
the user name and password first in the login page) and I am not sure
what to do after I run the code that I posted.

Thank you in advance

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '08 #3

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

Similar topics

0
by: Dan Greenblatt | last post by:
I am trying to programmatically manipulate the menus in my application, for purposes of a tutorial, showing users where things are in our application's menu interface. My goal is to be able to...
6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
1
by: Lumpierbritches | last post by:
Thank you in advance. Is there a way to programmatically fill an Unbound Form with a command button, using Queries built? I have a program that has about 10 different queries that all fill the...
4
by: debbie | last post by:
Well I'm finally trying out class modules...I have a great book I'm using but its ADO and I use DAO so it's a challenge for me...I've looked most of today, in my book and here but can not find an...
1
by: Anubis Cain Dante | last post by:
I am trying to programmatically clear the forms and passwords in internet explorer. I am well aware of how to do this (via the UI) in Internet Options and I've already accomplished programmatically...
6
by: nganapat | last post by:
I am trying to post form values to a https web page programmatically using Httpwebrequest but no matter what I do the same login page is returned instead of the next page. I would very much...
7
JodiPhillips
by: JodiPhillips | last post by:
Hi, My first post! I've basically taught myself Access and the little I know about VBA through reading these forums and a couple of books. I'm in the middle of a project at work - to put it...
6
by: pamela fluente | last post by:
Hello friends, I have a simple question. If I have an application with several forms, you see on the windows bar, usually on the bottom of your screen, the various tags for the various forms. ...
3
by: Peter | last post by:
Hi I want to programmatically perform a post. Can some one please give me some pointers to which classes I need to use to achieve this? The form which is normally posted from the website looks...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.