SDWebImage请求图片返回NSURLErrorDomain - Code = 404

出现问题SDWebImage版本号 2.7.4

1.1 图片加载请求失败 NSURLErrorDomain - Code = 404

{
但是用sdwebimage显示不了。 后来我换了另一个图片url是可以显示的。
最后,我直接下载这张图片,发现报错了:Error Domain=NSURLErrorDomain Code=404 
“The operation couldn’t be completed. (NSURLErrorDomain error 404.)” 
}

1.2 解决方法

{
///Mark: 设置 Downloader
    downloader.userInfo = userInfo;
    downloader.lowPriority = lowPriority;
    [downloader performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:YES];
    NSLog(@"下载图片地址:%@",downloader.url);

///MARK: 请求响应
-    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:15];
+    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:15];
     self.connection = SDWIReturnAutoreleased([[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO]);
+#ifdef SD_WEBP
+       [request setValue:@"image/webp,image/*;q=0.8" forHTTPHeaderField:@"Accept"];
+#else
+       [request setValue:@"image/*;q=0.8" forHTTPHeaderField:@"Accept"];
}

1.3 解释说明

{
406 Not Acceptable - The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request
}

1.4 代码截图

[代码截图]
屏幕快照 2017-11-15 上午9.20.19.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容