, NSHTTPURLResponse, cookie:
NSDictionary * headers = [(NSHTTPURLResponse *)response allHeaderFields];
NSArray * cookies = [NSHTTPCookie cookiesWithResponseHeaderFields:headers forURL:response.URL];
response - NSHTTPURLResponse.
NSURLResponses NSURLConnectionDelegate
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
NSHTTPCookie has a property propertiesthat returns NSDictionary, so you can save them. Then they can be created with the same dictionary using-initWithProperties:
To send them, you need to create your own cookie header line NSURLRequest. Sort of:
NSMutableString * cookieString = [[NSMutableString alloc] init];
for (NSHTTPCookie * cookie in myLoadedCookies){
[cookieString appendFormat:@"%@=%@; ", cookie.name, cookie.value];
}
[request setValue:cookieString forHTTPHeaderField:@"Cookie"];
[cookieString release];
Where request- NSMutableURLRequest.
You must also be sure that the iOS control core itself must be locked:
[request setHTTPShouldHandleCookies:NO]
source
share