I\'m trying to create an login in my iPhone App.
NSURL *urlNew = [NSURL URLWithString:urlstring];
NSMutableURLRequest *theRequest = [NSMutableURLRequest req
There is source code to extract cookie string from NSHTTPURLResponse
:
static NSString *CookieFromResponse(NSHTTPURLResponse *response) {
NSArray *cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:response.allHeaderFields forURL:response.URL];
NSMutableString *cookieStr = [NSMutableString string];
for (NSHTTPCookie *cookie in cookies) {
if (cookieStr.length) {
[cookieStr appendString:@"; "];
}
[cookieStr appendFormat:@"%@=%@", cookie.name, cookie.value];
}
return cookieStr.length ? cookieStr : nil;
}
And to set cookie string to NSMutableURLRequest
:
NSString *cookieStr = CookieFromResponse(response);
[request addValue:cookieStr forHTTPHeaderField:@"Cookie"];