简体   繁体   中英

AFNetworking content type for HEAD request for ios8

I have a HEAD request to certain image with If-modified-since HTTP header, in order to check if image is actually modified. If modified, then i just send GET request for this image. It used to work fine for iOS 7, And it works now for iOS 7. But for iOS 8 i got

Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: image/png" 

So the same code works for ios7 and for ios8- don't. Any ideas?

First, you don't need to make a HEAD request. An appropriate NSURLRequestCachePolicy can accomplish the same thing.

Second, the error is caused by an unacceptable content type being sent by the response for the response serializer. For image/png , use AFImageResponseSerializer , or set the appropriate acceptableContentTypes property for the response serializer of your choice.

Thanks Matt for showing the way. I removed HEAD request. Now i use AFHTTPRequestOperation with AFImageResponseSerializer. Also i set 'If-Modified-Since' header in NSMutableURLRequest with setValue:forHTTPHeaderField method. This date is stored in userdefaults, where key is URL, and value is the date where this URL was modified.

I'm sure there should be much better way for this, like using NSURLCache, but i couldn't do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM