本文介绍了Error Domain=NSURLErrorDomain Code=403 "操作无法完成.(NSURLErrorDomain 错误 403.)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 sdwebimage 和 back4app 后端.我们无法从 back4app 加载图片.
I am using sdwebimage and back4app backend . We are not able to load image from back4app.
[immg1 sd_setImageWithURL:url11 placeholderImage:[UIImage imageNamed:@"pro"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (error)
{
NSLog(@"B4A_Error: %@", error.localizedDescription);
NSLog(@"B4A_Error URL: %@", imageURL.absoluteString);
}
else
{
NSLog (@"B4A_Success");
[immg1 setNeedsDisplay];
}
}];
// [immg1 setImageWithURL:url11 usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[imgView addSubview:immg1];
推荐答案
由于某种原因,您的 SDWebImage
没有持久化 user-Agent
.我手动强制它在每次调用之前坚持.试试这个:
For some reason your SDWebImage
wasn’t persisting the user-Agent
. I manually forced it to persist before every call. Just try this:
NSString *userAgent = @"";
userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
if (userAgent) {
if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {
NSMutableString *mutableUserAgent = [userAgent mutableCopy];
if (CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, (__bridge CFStringRef)@"Any-Latin; Latin-ASCII; [:^ASCII:] Remove", false)) {
userAgent = mutableUserAgent;
}
}
[[SDWebImageDownloader sharedDownloader] setValue:userAgent forHTTPHeaderField:@"User-Agent"];
}
这篇关于Error Domain=NSURLErrorDomain Code=403 "操作无法完成.(NSURLErrorDomain 错误 403.)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!