0

I'm trying to get the headers of the NSURLRequest with the following line:

NSString *contentType = [[(NSHTTPURLResponse *)data allHeaderFields] valueForKey:@"Content-Type"];

but I'm getting the following error:

-[NSConcreteMutableData allHeaderFields]: unrecognized selector sent to instance 0x8d876e0
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData allHeaderFields]: unrecognized selector sent to instance 0x8d876e0'

Any of guys know why of this error or how can I fixed or what I'm doing wrong?

I'll really appreciate your help

HelenaM
  • 1,807
  • 6
  • 30
  • 41

1 Answers1

1

data is a NSData instance, not a NSHTTURLResponse as you think.

That's why it doesn't recognize the selector allHeaderFields that you're sending to it.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
  • got it. I was calling in the wrong place:- (void)connection:(NSURLConnection *)detailConnection didReceiveResponse:(NSURLResponse *)response { self.responseData = [NSMutableData data]; NSString *contentType = [[(NSHTTPURLResponse *)response allHeaderFields] valueForKey:@"Content-Type"]; – HelenaM Apr 06 '13 at 06:37