T
TJO
I am working with the HttpWebRequest agains a simple aspx page that I
created. The page has two panels one for the input of two html input boxes
and the secone panel that displays the values of the input boxes on
postback.
I make my first web GET request like this:
objRequest1 = (HttpWebRequest)System.Net.HttpWebRequest.Create(uri);
objRequest1.Method = "GET";
objRequest1.ContentType = "text/html";
objRequest1.CookieContainer = new CookieContainer();
objRequest1.AllowAutoRedirect = true;
objResponse1 = (HttpWebResponse)objRequest1.GetResponse();
sr = new StreamReader(objResponse1.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
I then receive a session cookie that I put in my 2nd request like this:
string postData = "txt_name=tim&txt_address=261 Trailway"
objRequest2 = (HttpWebRequest)System.Net.HttpWebRequest.Create(uri);
objRequest2.Method = "POST";
objRequest2.AllowAutoRedirect = true;
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "application/x-www-form-urlencoded";
objRequest2.Timeout = 100000;
objRequest2.CookieContainer = new CookieContainer();
objRequest2.CookieContainer.Add(objResponse1.Cookies);
myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
sr = new StreamReader(objResponse2.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
I am hoping this 2nd request trigger the postback and therefore the output
data in the 2nd panel but it does not. What am I doing wrong?
Thank for you help.
created. The page has two panels one for the input of two html input boxes
and the secone panel that displays the values of the input boxes on
postback.
I make my first web GET request like this:
objRequest1 = (HttpWebRequest)System.Net.HttpWebRequest.Create(uri);
objRequest1.Method = "GET";
objRequest1.ContentType = "text/html";
objRequest1.CookieContainer = new CookieContainer();
objRequest1.AllowAutoRedirect = true;
objResponse1 = (HttpWebResponse)objRequest1.GetResponse();
sr = new StreamReader(objResponse1.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
I then receive a session cookie that I put in my 2nd request like this:
string postData = "txt_name=tim&txt_address=261 Trailway"
objRequest2 = (HttpWebRequest)System.Net.HttpWebRequest.Create(uri);
objRequest2.Method = "POST";
objRequest2.AllowAutoRedirect = true;
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "application/x-www-form-urlencoded";
objRequest2.Timeout = 100000;
objRequest2.CookieContainer = new CookieContainer();
objRequest2.CookieContainer.Add(objResponse1.Cookies);
myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
sr = new StreamReader(objResponse2.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
I am hoping this 2nd request trigger the postback and therefore the output
data in the 2nd panel but it does not. What am I doing wrong?
Thank for you help.