CookieContainer GetCookies fails on multiple Set-Cookies

G

guyhey

I am accessing a site that passes the following headers:
Set-Cookie: ASP.NET_SessionId=pwdciy45i0c5me45urxjfoi0; path=/
Set-Cookie: LastSessID=pwdciy45i0c5me45urxjfoi0; expires=Tue,
01-Mar-2016 20:07:11 GMT; path=/
Set-Cookie: pubAccID=04; expires=Tue, 01-Mar-2016 20:07:11 GMT; path=/

I have verified this using ieHttpHeaders

When I use asp.net

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.AllowAutoRedirect = autoRedirect;
req.MaximumResponseHeadersLength = -1;
req.Timeout = timeout;
req.CookieContainer = new CookieContainer();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
res.Cookies = req.CookieContainer.GetCookies(req.RequestUri);

It only captures "Set-Cookie:
ASP.NET_SessionId=pwdciy45i0c5me45urxjfoi0; path=/"

Am I doing something wrong? Is there a way for me to get all the
headers.

Thanks
 
Joined
Jan 12, 2008
Messages
1
Reaction score
0
hey guyhey,
apologize for 2 year delay. :)
always its better to get the cookies from the header and then parse.
here i explained the steps. that may help others
the below code i used in my project contacts reader .net
you can get the project at http://www.ideabubbling.com/contactsreader.aspx

httpreqAddYahooCom.CookieContainer.GetCookies(reqAddYahooCom.RequestUri);
instead of calling CookieContainer.GetCookies() method
try the following:

just add the below file: utility.cs into your project
you can use the following statements to get all the cookies

string AllCookiesHeader = resFirstPage.Headers["Set-Cookie"];
string strUrl = "www.yahoo.com";
CookieCollection ss= Utility.GetAllCookiesFromHeader(AllCookiesHeader, strUrl);


love zvasanth
 

Attachments

  • utility.txt
    12.3 KB · Views: 611

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top