Saturday, May 11, 2013

NSHTTPURLResponse allHeaderFields example ios


allHeaderFields

Returns all the HTTP header fields of the receiver.
- (NSDictionary *)allHeaderFields
Return Value of [NSHTTPURLResponse allHeaderFields]
A dictionary containing all the HTTP header fields of the receiver. By examining this dictionary clients can see the “raw” header information returned by the HTTP server.
Example of [NSHTTPURLResponse allHeaderFields]
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSString *lastModifiedString = nil;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
  if ([httpResponse respondsToSelector:@selector(allHeaderFields)]) {
    lastModifiedString = [[httpResponse allHeaderFields] objectForKey:@"Last-Modified"];
  }
  // [Here is where the formatting-date-code and downloading would take place]
}
Example of [NSHTTPURLResponse allHeaderFields]
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
  NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
  NSString *lastModifiedString = [[httpResponse allHeaderFields] objectForKey:@"Last-Modified"];
  // [Here is where the formatting-date-code and downloading would take place]
}