SDWebImage 报错Error Domain=NSURLErrorDomain Code=403 “The operation couldn’t be completed. (NSURLErrorDomain error 403.)”

首先排除ios9   ATS的设置问题。

1、SDWebImage可以正常加载HTTPS的图片。

2、SDWebImage可以加载有些HTTP图片。

3、SDWebImage不能加载有些HTTP的图片,但是网页上打开,或者UIWebView可以正常加载。

排除了所有可能的问题。

找到这个答案:Stackflow

For some reason yourSDWebImagewasn’t persisting theuser-Agent

以下代码贴上使用。即可加载部分不能加载的图片。

NSString*userAgent=@"";userAgent=[NSStringstringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)",[[[NSBundlemainBundle]infoDictionary]objectForKey:(__bridgeNSString*)kCFBundleExecutableKey]?:[[[NSBundlemainBundle]infoDictionary]objectForKey:(__bridgeNSString*)kCFBundleIdentifierKey],[[[NSBundlemainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"]?:[[[NSBundlemainBundle]infoDictionary]objectForKey:(__bridgeNSString*)kCFBundleVersionKey],[[UIDevicecurrentDevice]model],[[UIDevicecurrentDevice]systemVersion],[[UIScreenmainScreen]scale]];if(userAgent){if(![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]){NSMutableString*mutableUserAgent=[userAgent mutableCopy];if(CFStringTransform((__bridgeCFMutableStringRef)(mutableUserAgent),NULL,(__bridgeCFStringRef)@"Any-Latin; Latin-ASCII; [:^ASCII:] Remove",false)){userAgent=mutableUserAgent;}}[[SDWebImageDownloadersharedDownloader]setValue:userAgent forHTTPHeaderField:@"User-Agent"];}

你可能感兴趣的:(SDWebImage 报错Error Domain=NSURLErrorDomain Code=403 “The operation couldn’t be completed. (NSURLErrorDomain error 403.)”)