Get cookies using iPhone SDK

by alex 14. May 2009 09:44

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); 

}

 

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen