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

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:password=XXXXX&_ctl1:S igninBtn.x=0&_ctl1:SigninB
tn.y=0";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteData = encoding.GetBytes(postData);
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/XXXX/default.aspx");
objRequest.Method = "POST";
objRequest.ContentLength = postData.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.CookieContainer = new CookieContainer();

try
{
requestWriter = objRequest.GetRequestStream();
requestWriter.Write(byteData, 0, byteData.Length);
}
catch(Exception e)
{
System.Console.WriteLine(e.Message);
}
finally
{
requestWriter.Close();
}

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
StreamReader responseReader = null;
responseReader = new StreamReader(objResponse.GetResponseStream());
string result = responseReader.ReadToEnd();

System.Console.WriteLine(result);
System.IO.StreamWriter fileWriter = null;
fileWriter =
System.IO.File.CreateText("c:\\work\\XXXX\\testpos tdata.html");
fileWriter.Write(result);
fileWriter.Close();

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

Ollie
Nov 16 '05 #1
1 1907
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**********@hotmail.com> wrote in message
news:#Z**************@tk2msftngp13.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:password=XXXXX&_ctl1:S igninBtn.x=0&_ctl1:SigninB tn.y=0";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteData = encoding.GetBytes(postData);
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/XXXX/default.aspx");
objRequest.Method = "POST";
objRequest.ContentLength = postData.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.CookieContainer = new CookieContainer();

try
{
requestWriter = objRequest.GetRequestStream();
requestWriter.Write(byteData, 0, byteData.Length);
}
catch(Exception e)
{
System.Console.WriteLine(e.Message);
}
finally
{
requestWriter.Close();
}

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
StreamReader responseReader = null;
responseReader = new StreamReader(objResponse.GetResponseStream());
string result = responseReader.ReadToEnd();

System.Console.WriteLine(result);
System.IO.StreamWriter fileWriter = null;
fileWriter =
System.IO.File.CreateText("c:\\work\\XXXX\\testpos tdata.html");
fileWriter.Write(result);
fileWriter.Close();

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
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...
1
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...
5
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...
3
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...
1
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...
0
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...
9
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...
20
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...
3
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 +...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
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
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.