views:

50

answers:

1

I do this, but the new cookie doesn't show up, just some other cookies that are already set. What's wrong?

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:[NSHTTPCookie cookieWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                             @"www.mydomain.com", NSHTTPCookieOriginURL,
                                                                                             @"/", NSHTTPCookiePath,
                                                                                             @"mycookiename", NSHTTPCookieName,
                                                                                             @"mycookievalue", NSHTTPCookieValue,
                                                                                             nil]]];
 NSLog(@"%@",[NSHTTPCookieStorage sharedHTTPCookieStorage]);
+1  A: 

Have you tried putting an NSURL into the NSHTTPCookieOriginURL property?

NSURL *originURL = [NSURL URLWithString:@"http://www.mydomain.com"];

It looks like you can use an NSString or an NSURL, but either way the URL you specify must conform to the standards outlined in RFC 2396 (e.g. "http://x.y.z", etc.).

Also make sure you're not overlooking any other required cookie properties or formatting of those properties.

Alex Reynolds
NSURL did the job! Thanks!Note that NSLog(@"%@",[NSHTTPCookieStorage sharedHTTPCookieStorage]) will trow an exception in this case (don't know why) but NSLog(@"%@",[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) will work.
Nick Dima