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

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

문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top