NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:url]];
for (NSHTTPCookie *cookie in cookies){
// cookiesWithResponseHeaderFields方法,需要为URL设置一个cookie为NSDictionary类型的header,注意NSDictionary里面的forKey需要是@"Set-Cookie"
NSArray *headeringCookie = [NSHTTPCookie cookiesWithResponseHeaderFields:
[NSDictionary dictionaryWithObject:
[[NSString alloc] initWithFormat:@"%@=%@",[cookie name],[cookie value]]
forKey:@"Set-Cookie"]
forURL:urlString];
// 通过setCookies方法,完成设置,这样只要一访问URL为HOST的网页时,会自动附带上设置好的header
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:headeringCookie
forURL:[NSURL URLWithString:url]
mainDocumentURL:nil];
}
for (NSHTTPCookie *cookie in cookies){
// cookiesWithResponseHeaderFields方法,需要为URL设置一个cookie为NSDictionary类型的header,注意NSDictionary里面的forKey需要是@"Set-Cookie"
NSArray *headeringCookie = [NSHTTPCookie cookiesWithResponseHeaderFields:
[NSDictionary dictionaryWithObject:
[[NSString alloc] initWithFormat:@"%@=%@",[cookie name],[cookie value]]
forKey:@"Set-Cookie"]
forURL:urlString];
// 通过setCookies方法,完成设置,这样只要一访问URL为HOST的网页时,会自动附带上设置好的header
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:headeringCookie
forURL:[NSURL URLWithString:url]
mainDocumentURL:nil];
}