473,772 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

posting daqta to an asp.net page from a console application

I have an aspx page that contains a web control that contains 2 text boxes
and button to submit the text. I am trying to submit text and collect the
response from a console application, but it is not working correctly it is
just returning the original page I am expecting it to return the a
subsequent page (when a successfull login has occurred), the code is shown
below.

Does anyone know why it is not working correctly?

I used the Fiddler app to debug the HTTP header to work out the posting data
( nice app Eric :) )

Stream requestWriter = null;
string postData =
"_ctl1:username =ollie&_ctl1:pa ssword=XXXXX&_c tl1:SigninBtn.x =0&_ctl1:Signin B
tn.y=0";
ASCIIEncoding encoding = new ASCIIEncoding() ;
byte[] byteData = encoding.GetByt es(postData);
HttpWebRequest objRequest =
(HttpWebRequest )WebRequest.Cre ate("http://localhost/XXXX/default.aspx");
objRequest.Meth od = "POST";
objRequest.Cont entLength = postData.Length ;
objRequest.Cont entType = "applicatio n/x-www-form-urlencoded";
objRequest.Cook ieContainer = new CookieContainer ();

try
{
requestWriter = objRequest.GetR equestStream();
requestWriter.W rite(byteData, 0, byteData.Length );
}
catch(Exception e)
{
System.Console. WriteLine(e.Mes sage);
}
finally
{
requestWriter.C lose();
}

HttpWebResponse objResponse = (HttpWebRespons e)objRequest.Ge tResponse();
StreamReader responseReader = null;
responseReader = new StreamReader(ob jResponse.GetRe sponseStream()) ;
string result = responseReader. ReadToEnd();

System.Console. WriteLine(resul t);
System.IO.Strea mWriter fileWriter = null;
fileWriter =
System.IO.File. CreateText("c:\ \work\\XXXX\\te stpostdata.html ");
fileWriter.Writ e(result);
fileWriter.Clos e();

System.Console. ReadLine();
Cheers and thanks in advance

Ollie
Nov 16 '05 #1
1 1921
posting to an aspx.net page requires that you first do a Get and parse the
html for the viewstate value, so that you have a valid __Viewstate to
postback.

-- bruce (sqlwork.com)
"Ollie" <ol**********@h otmail.com> wrote in message
news:#Z******** ******@tk2msftn gp13.phx.gbl...
I have an aspx page that contains a web control that contains 2 text boxes
and button to submit the text. I am trying to submit text and collect the
response from a console application, but it is not working correctly it is
just returning the original page I am expecting it to return the a
subsequent page (when a successfull login has occurred), the code is shown
below.

Does anyone know why it is not working correctly?

I used the Fiddler app to debug the HTTP header to work out the posting data ( nice app Eric :) )

Stream requestWriter = null;
string postData =
"_ctl1:username =ollie&_ctl1:pa ssword=XXXXX&_c tl1:SigninBtn.x =0&_ctl1:Signin B tn.y=0";
ASCIIEncoding encoding = new ASCIIEncoding() ;
byte[] byteData = encoding.GetByt es(postData);
HttpWebRequest objRequest =
(HttpWebRequest )WebRequest.Cre ate("http://localhost/XXXX/default.aspx");
objRequest.Meth od = "POST";
objRequest.Cont entLength = postData.Length ;
objRequest.Cont entType = "applicatio n/x-www-form-urlencoded";
objRequest.Cook ieContainer = new CookieContainer ();

try
{
requestWriter = objRequest.GetR equestStream();
requestWriter.W rite(byteData, 0, byteData.Length );
}
catch(Exception e)
{
System.Console. WriteLine(e.Mes sage);
}
finally
{
requestWriter.C lose();
}

HttpWebResponse objResponse = (HttpWebRespons e)objRequest.Ge tResponse();
StreamReader responseReader = null;
responseReader = new StreamReader(ob jResponse.GetRe sponseStream()) ;
string result = responseReader. ReadToEnd();

System.Console. WriteLine(resul t);
System.IO.Strea mWriter fileWriter = null;
fileWriter =
System.IO.File. CreateText("c:\ \work\\XXXX\\te stpostdata.html ");
fileWriter.Writ e(result);
fileWriter.Clos e();

System.Console. ReadLine();
Cheers and thanks in advance

Ollie

Nov 16 '05 #2

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

Similar topics

0
1108
by: DS | last post by:
Hi all, Any help is greatly appreciated! I am trying to convert HTML pages into mht. I used code from http://www.eggheadcafe.com/articles/20040527.asp. I would like to create a small utility (console application) for performing the task. While asp page works fine, executing same code in console application project gives following error:
1
5387
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
5
11258
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough to avoid the overhead of writing to the console if it is not visible, eg I am running inside a WinForm application. thanks
3
5772
by: Jeffery Tyree | last post by:
All I would like is one example of working code that does nothing more than submit a search criteria to Google and print to console the resulting page of found items. To make it easier, below is my code. Simply correct it in place so that I may copy/paste it back into the IDE and run it. Please do not tell me to do net sniff comparisons or make sure I have the right control values. If I knew these things I wouldn't be here asking,...
1
1069
by: Ollie | last post by:
I have an aspx page that contains a web control that contains 2 text boxes and button to submit the text. I am trying to submit text and collect the response from a console application, but it is not working correctly it is just returning the original page I am expecting it to return the a subsequent page (when a successfull login has occurred), the code is shown below. Does anyone know why it is not working correctly? I used the...
0
1174
by: andy | last post by:
Hi, I'm trying to call an SAP Rfc from my .net application using the .Net SAP connector. I have to create a console application and through that I have to call the SAP RFC. I have been able to do so through a webform (.aspx) but am not able to do so through a console application. The first problem I faced was in opening a connection in the webform I could open a new connection as shown below ...
9
2749
by: Mike | last post by:
Hi, I have the following problem: I have a singleton class that I want to access from asp.net application. The trick is, that I want to create it (Singleton.GetInstance() for the first time) in console application. In other words, I want the following to happen: 1. start console application 2. create object 3. start asp.net and pass the object reference 4. after some time, user surfs to asp.net page, and sees some
20
2720
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in contrast to one of them always being 'modal' (e.g., if you are moving over a picture the 'Info' form will update the (x,y) screen location in realtime even if not the selected form. Also note that this example implies the various forms can communicate...
3
3449
by: TheOne | last post by:
I'm newbie. I tried to compile and excute this super simple code. == codestart == class Sample1 { static void Main() { string person; person = "ÀÌÈ¿¸®¾¾"; System.Console.WriteLine(person + ", ¾È³çÇϼ¼¿ä"); System.Console.WriteLine(person + ", ¿À·¡°£¸¸ÀÔ´Ï´Ù");
0
9454
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
10106
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
10039
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,...
1
7461
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
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
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...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.