ios get the headers from NSURLRequest I get error [NSConcreteMutableData allHeaderFields]: unrecognized selector

StackOverflow https://stackoverflow.com/questions/15847737

Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top