SDWebImage : NSURLErrorDomain - Code = 406

Solution:Overriding request headers in SDWebImage

Looking for the file "SDWebImageDownloader.m"

replace

#ifdef SD_WEBP
        _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy];
#else
        _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy];
#endif

to

#ifdef SD_WEBP
        _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy];
#else
        _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8;q=0.9,*/*"} mutableCopy];
#endif

SDWebImageDownloader is a Singleton object in iOS

so we could set a custom header value to 'Accept' header to override the default header.

[SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
                             forHTTPHeaderField:@"Accept"];
[self.imageView sd_setImageWithURL:[self imageUrlForId:imageId] placeholderImage:image];

 

posted @ 2016-03-17 11:20  N了歌C  阅读(417)  评论(0编辑  收藏  举报