I have to set NSHTTPCookie such that it expiry is set to Session. I used the following code to set properties of that cookie.
NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"mycookiename" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"mycookievalue" forKey:NSHTTPCookieValue];
[cookieProperties setObject:[NSNumber numberWithBool:TRUE] forKey:NSHTTPCookieSecure];
[cookieProperties setObject:@"com.mydomain" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"com.mydomain" forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
However both of the above properties set the expiry to 1 Jan 2001 02:00:00 GMT+2 rather than setting the expiry to Session
You should have a look at sessionOnly property. Apple Documentation
It says:
You can also have a look at the superb library ASIHTTPRequest
It has some nice methods that can help you. From their How-To:
So you might want to create a
NSHTTPCookie
with no expiration date set.This information can also be found in the Apple Docs:
To do so: