MugunthKumar/MKNetworkKit — Issue #18: NSHTTPCookieStorage with MKNetworkKit
Author: saturngod
Created: 2011-12-28 17:07:46+00:00
State: open

I used RestKit with Cookie is working fine. When I try to use with MKNetworkKit , cookie is not working.

I use

NSArray* cookies=[loginModel setCookie];

for(NSHTTPCookie * cookie in cookies) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}

+(NSArray*)setCookie {
NSString* html=[[NSUserDefaults standardUserDefaults] objectForKey:@"cookie"];
NSArray * items = [html componentsSeparatedByString:@"\n"];

NSMutableArray* cookies = [[NSMutableArray alloc] init];

NSArray * parts;
NSString * cName;
NSString * cValue;

for(NSString * c in items) {
parts = [c componentsSeparatedByString:@"="];
if([parts count] == 2) {
cName = [parts objectAtIndex:0];
cValue = [parts objectAtIndex:1];

NSMutableDictionary * cookieProperties = [[NSMutableDictionary alloc] init];
[cookieProperties setValue:cName forKey:NSHTTPCookieName];
[cookieProperties setValue:cValue forKey:NSHTTPCookieValue];
[cookieProperties setValue:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setValue:@".google.com" forKey:NSHTTPCookieDomain];

NSHTTPCookie * cookie = [[NSHTTPCookie alloc] initWithProperties:cookieProperties];

[cookies addObject:cookie];
[cookie release], cookie = nil;
[cookieProperties release], cookieProperties = nil;
}
} // end for
return cookies;
}