473,808 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Post Forms Programmaticall y

Hello,

I would like to know how to post form data programmaticall y. The idea is
to get the intranet web page, programmaticall y 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.Cre ate(url);
string proxy = null;

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

req.Method = "POST";
req.ContentType = "applicatio n/x-www-form-urlencoded";
req.ContentLeng th = buffer.Length;
req.Proxy = new WebProxy(proxy, true); // ignore for local
addresses
req.CookieConta iner = new CookieContainer ();
Stream reqst = req.GetRequestS tream(); // add form data to request
stream
reqst.Write(buf fer, 0, buffer.Length);
reqst.Flush();
reqst.Close();

*** Sent via Developersdex http://www.developersdex.com ***
Aug 19 '08 #1
2 2448
David wrote:
I would like to know how to post form data programmaticall y. The idea is
to get the intranet web page, programmaticall y 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.Cre ate(url);
string proxy = null;

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

req.Method = "POST";
req.ContentType = "applicatio n/x-www-form-urlencoded";
req.ContentLeng th = buffer.Length;
req.Proxy = new WebProxy(proxy, true); // ignore for local
addresses
req.CookieConta iner = new CookieContainer ();
Stream reqst = req.GetRequestS tream(); // add form data to request
stream
reqst.Write(buf fer, 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 programmaticall y (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
1289
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 programmatically say 'show the menu cascade: Menu1 Menu2 Menu3 Action' and these menus will post as they would if they were being scrolled over by the mouse.
6
2873
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 loop through all the forms in a database and pull information about the form (controls and properties). We would need to do the same in our VB.NET project; loop through the project and get the web form's control and property information...
1
1416
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 same form, same fields etc. So I have 10 queries and 10 forms for each query. I was wondering to keep bloat down, can you programmatically fill a form with ten different queries, if all the fields are identical? If so, How? Michael
4
3067
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 answer. Is it possible to use the class I've created to fill a continuous form? Not finding any information leads me to believe that it can't be done... I have a continuous form that shows all invoices with a balance due...I'm hoping to use the...
1
1787
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 clearing the cache and the cookies with the wininet API. Are there any API's that allow me to do this? I also notice that even though I clear my cache (via the UI OR programmatically) the index.dat files still hold all of my information. How do I...
6
7817
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 appreciate if someone could show me what is it that I am doing wrong. Below is the code that I am using. string viewstate = HttpUtility.UrlEncode(viewstatevalue); StringBuilder data = new StringBuilder(); data.Append("VAM_Group=");...
7
4779
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 mildly I've been thrown in at the deep end, in the past I've just done simple databases and that's been fine. Now, however I have to "roll out" various front ends to a single back end for initially 10 users (and the bosses have plans for this to go to...
6
1099
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. Now if the bar gets crowded, windows automatically puts all the minimized forms of the same application together, and indicates how many of them are collapsed in that tag.
3
2283
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 like the following, but I want to do it programmatically. <form action="https://intl.payments/recdpay" method="POST"
0
9721
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
10631
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...
0
10374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9196
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
7651
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
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3859
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.