IOS将在连接委托中使用QueryResponse

时间:2013-07-08 14:15:44

标签: ios caching nsurlconnection restkit-0.20 nsurlconnectiondelegate

我想知道哪个方法是验证部分,它将识别响应中的缓存控制标头,并将调用connection:willCacheResponse:委托。

因为我在这里定制了响应标头,并且期望NSURLConnection调用connection:willCacheResponse:,但这种情况并未发生。

- (void)connection:(NSURLConnection __unused *)connection

didReceiveResponse:(NSURLResponse *)回复 {

NSHTTPURLResponse *httpresponse = (NSHTTPURLResponse *)response;
NSLog(@"headers : %@", [httpresponse allHeaderFields]);
NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionary];
[mutableDictionary addEntriesFromDictionary:[httpresponse allHeaderFields]];
[mutableDictionary setObject:@"public, must-revalidate, max-age=300000" forKey:@"Cache-Control"];
NSURLRequest *urlRequest = [connection currentRequest];

NSInteger statusCode = 200;
//id headerFields = nil;
NSURL *urlString = urlRequest.URL;
NSString* HTTPVersion = nil;
SEL selector = NSSelectorFromString(@"initWithURL:statusCode:HTTPVersion:headerFields:");
NSMethodSignature *signature = [self methodSignatureForSelector:selector];
    NSInvocation *inv = [NSInvocation invocationWithMethodSignature:signature];
[inv setTarget:httpresponse];
[inv setSelector:selector];
[inv setArgument:&urlString atIndex:2];
[inv setArgument:&statusCode atIndex:3];
[inv setArgument:&mutableDictionary atIndex:5];
[inv setArgument:&HTTPVersion atIndex:4];
[inv invoke];    

NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)self.response;
int code = [httpResponse statusCode];
NSLog(@"response status code : %d", code);
if ([self.response respondsToSelector:@selector(allHeaderFields)]) {
    NSDictionary *dictionary = [httpResponse allHeaderFields];
    NSLog(@"Header Discription:%@", [dictionary description]);
}

[self.outputStream open];

}

0 个答案:

没有答案