"Get cookies using iPhone SDK"

Thu 14 May 2009

NSHTTPURLResponse * response;

NSError * error;

NSMutableURLRequest request;

request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://google.com/"]

cachePolicy:NSURLRequestReloadIgnoringCacheData 

timeoutInterval:60] autorelease];

NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

 

NSLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]);

NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://google.com/"]];

NSLog(@"%d", all.count);

 

for (NSHTTPCookie cookie in all) {

NSLog(@"Name: %@ : Value: %@", cookie.name, cookie.value); 

}