iOS 获取请求Cookies和header信息

1.获取cookies

- (void)getCookies {
    NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray *cookieArr = [cookieJar cookies];
    for(NSHTTPCookie *cookie in cookieArr) {
        if ([cookie.name isEqualToString:@"salt"]) {
            //存储cookies
            _cookie = cookie.value;
        }
        //存储之后删除cookies
        [cookieJar deleteCookie:cookie];
    }
}

2.获取header信息

NSURLResponse * _Nullable response.......
NSHTTPURLResponse *r = (NSHTTPURLResponse *)response;
NSDictionary *dict = [r allHeaderFields];
self.cookie = dict[@"salt"];

你可能感兴趣的:(iOS 获取请求Cookies和header信息)