CookieContainer GetCookies fails on multiple Set-Cookies

Discussion in 'ASP .Net' started by guyhey, Mar 1, 2006.

  1. guyhey

    guyhey Guest

    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
    guyhey, Mar 1, 2006
    #1
    1. Advertising

  2. guyhey

    guyhey Guest

    can someone tell me if there is a better way to get cookies at least?

    guyhey wrote:
    > 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
    guyhey, Mar 7, 2006
    #2
    1. Advertising

  3. guyhey

    zvasanth

    Joined:
    Jan 12, 2008
    Messages:
    1
    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

    Attached Files:

    zvasanth, Jan 12, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. macro
    Replies:
    4
    Views:
    5,035
    macro
    Mar 29, 2006
  2. Kaspar Minosiants

    [Q] HttpServletRequest.getCookies()

    Kaspar Minosiants, Jul 8, 2003, in forum: Java
    Replies:
    2
    Views:
    2,295
    Kaspar Minosiants
    Jul 9, 2003
  3. Dobedani
    Replies:
    1
    Views:
    11,245
    Anton Spaans
    Jun 28, 2005
  4. _Who
    Replies:
    7
    Views:
    2,630
  5. macro
    Replies:
    4
    Views:
    186
    macro
    Mar 29, 2006
Loading...

Share This Page