1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

httpwebrequest Cookie object throwing exception

Discussion in 'C, C++, C#' started by xpro, Oct 23, 2010.

  1. xpro

    xpro Regular Member

    Joined:
    Jan 21, 2009
    Messages:
    426
    Likes Received:
    22
    Hello

    For the past 2 weeks I've been trying to login to Hotmail without success, I found out that some cookies are not being passed. I've attached the fiddler's screen shot which shows the cookies in the server response.

    I found out that the first cookie
    "MSPRequ=lt=1287096700&co=1&id=64855; path=/;version=1" does get added to the cookie container but the second one

    "MSPOK=$uuid-33b7d7e6-4b2b-48da-84dc-51eba83871ba; domain=login.live.com;path=/;version=1"

    never gets added, so I decided to parse it out from the response headers and add it manually.

    Code:
    cookieContainer.Add(new Uri(incomingUrl), new Cookie("MSPOK", "$uuid-94923791-c0d6-43f2-ac78-dba34acd86cb; domain=login.live.com;path=/;version=1"));
    
    
    But when adding the cookie I get the following exception

    "System.Net.CookieException: The 'Value'='$uuid-94923791-c0d6-43f2-ac78-dba34acd86cb; domain=login.live.com;path=/;version=1' part of the cookie is invalid."

    Any idea what I can do?


    Best Regards!
     

    Attached Files:

  2. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    80
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    looks to me like you're overloading the constructor for the new cookie object incorrectly.

    Code:
    http://msdn.microsoft.com/en-us/library/system.net.cookie.aspx
    the constructor on the cookie has 4 overloads, it looks like the one you actually want to be using is this one:

    Code:
    http://msdn.microsoft.com/en-us/library/a18ka3h2.aspx
    so split out the path, domain, and leave off the version. also i don't believe you need to passing any of the ; with it.

    what you're doing is trying to use the constructor that only takes name and value, but when it looks it at that value it is seeing all kinds of different information including the separating ;

    set up your constructor like this and it should work:

    Code:
    new Cookie("MSPOK","$uuid-94923791-c0d6-43f2-ac78-dba34acd86cb","/","login.live.com");
     
    • Thanks Thanks x 1
  3. xpro

    xpro Regular Member

    Joined:
    Jan 21, 2009
    Messages:
    426
    Likes Received:
    22
    it worked :) I would have never thought of that. Thanks and Rep given :)
     
  4. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    80
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    awesome, thanks. glad i could help. :)