473,396 Members | 1,777 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,396 software developers and data experts.

Sending Cookies on a WebRequest object, times out

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.

Nov 17 '05 #1
2 1695
Sorry. I didnt include the question.

When I send the Cookie header, the request times out, but
when I don't include cookies (either by using the Cookie
header or using the CookieContainer object) the
application retrieves the data very fast.

How can I send cookies using a HttpWebRequest object? Any
help will be much appreciated.

-----Original Message-----
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.
.

Nov 17 '05 #2
Hi,

First I run your code on my machine and it work like charm.

If you want to call other page in order to embed its HTML in to your
page you can use Server.Execute().

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3

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

Similar topics

0
by: Michael Evanchik | last post by:
Hello all, since i wanted to use ssl and its seems easy to do so with this object. Im trying to login to a webserver (aol) for this example. But for some reason, im packet sniffing with ethreal...
0
by: Pat Allan | last post by:
I've spent half a day on this with no success, so I'm hoping someone can point out what I'm doing wrong. I have an ASP.NET Server-side component that I've created, and as part of its Render...
1
by: Ravi | last post by:
Hi , i am trying to pass the same session Id to all the webrequest, but sometimes the response.cookies returns zero and sometimes one. is this to do something with cookies expire. In this sample...
9
by: Michael Evanchik | last post by:
Hello all, since i wanted to use ssl and its seems easy to do so with this object. Im trying to login to a webserver (aol) for this example. But for some reason, im packet sniffing with ethreal...
3
by: Beryl Small | last post by:
Hi, I have a third party software that needs to send information to an .aspx page for processing to communicate with an SQL database. The software sends the information something like this: ...
9
by: Justin Engelman | last post by:
Hi, I have a website that uses an ISAPI filter that will redirect anyone going to any page on the site to an SSL login page (on a different website with the same root domain) if they do not have...
0
by: Tony Archer | last post by:
Here's my problem... When I use this code to hit the site in question I'm redirected to another SSL login page. If processed successfully the page creates a cookie and then redirects you to the...
2
by: Issos | last post by:
Is there a way to just receive the cookie(s) from an webrequest in ASP.NET? The function I'm using at the moment can handle cookies... but it will also get the full response of the request... I...
1
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.