A
Andres
I am creating a web request (HttpWebRequest) from a web
page in order to retrieve the Html from another page and
embed it in the calling page. When you create a
HttpWebRequest the request is created empty, so I need to
populate its headers in order to send cookies for
authentication purposes.
This is the code fragment:
....
//Create requests
HttpWebRequest req = (HttpWebRequest) WebRequest.Create
(targetUrl);
//Populate some headers explicitly.
req.UserAgent = Context.Request.Headers["User-Agent"];
req.Accept = Context.Request.Headers["Accept"];
req.ContentType = Context.Request.Headers["Content-Type"];
/* If i comment out the next line, the code will work fine,
otherwise, it will generate a timeout error */
req.Headers.Add("Cookie", Context.Request.Headers
["Cookie"]);
//Create the response object from the request.
WebResponse resp = req.GetResponse();
//Create a reader where I can read the html from the
response.
StreamReader rdr = new StreamReader(resp.GetResponseStream
());
//Write somewhere the html. for now in the output window.
System.Diagnostics.Debug.WriteLine(rdr.ReadToEnd());
Any help will be very much appreciated.
Andres.
page in order to retrieve the Html from another page and
embed it in the calling page. When you create a
HttpWebRequest the request is created empty, so I need to
populate its headers in order to send cookies for
authentication purposes.
This is the code fragment:
....
//Create requests
HttpWebRequest req = (HttpWebRequest) WebRequest.Create
(targetUrl);
//Populate some headers explicitly.
req.UserAgent = Context.Request.Headers["User-Agent"];
req.Accept = Context.Request.Headers["Accept"];
req.ContentType = Context.Request.Headers["Content-Type"];
/* If i comment out the next line, the code will work fine,
otherwise, it will generate a timeout error */
req.Headers.Add("Cookie", Context.Request.Headers
["Cookie"]);
//Create the response object from the request.
WebResponse resp = req.GetResponse();
//Create a reader where I can read the html from the
response.
StreamReader rdr = new StreamReader(resp.GetResponseStream
());
//Write somewhere the html. for now in the output window.
System.Diagnostics.Debug.WriteLine(rdr.ReadToEnd());
Any help will be very much appreciated.
Andres.