2

我写了一个 WS,它提供的其中一件事是头像(上传和服务器)。唯一的问题是,每当我尝试使用 SDWebImage (UIButton+SDWebImage) 访问一个时,我的完成处理程序中都会出现上述错误。完整的错误是: (Error Domain=NSURLErrorDomain Code=406 "The operation could not be completed. (NSURLErrorDomain error 406.)" ) 奇怪的是服务器没有被触及(登录验证这个)!任何想法可能导致此问题以及如何解决?

PS如果我NSLog URL,然后将其复制并粘贴到浏览器中,它可以完美运行,所以它与SDWebImage或iOS有关。

编辑有问题的代码:

[btn setBackgroundImageWithURL:url forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"user-empty.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
                    if (error) {
                        NSLog(@"error loading image:%@",error);
                        return;
                    }
                    NSLog(@"image should be loaded");
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [btn setBackgroundImage:image forState:UIControlStateHighlighted];
                    });
                }];

至于网址我宁愿不分享,因为我们目前没有域名,我不想给出我客户服务器的 ip……我相信你明白,但这里是url 减去正确的 ip(请注意,我必须添加空格才能发布编辑,它们不在实际 url 中):http://192 .168 .1 .21/uploads/51078f979c966bde0b000009/avatar.png

会不会是我的 WS 的问题?关于标题的东西还是什么?我知道它会发回“image/png”的内容类型,如果这有帮助的话,就像我说它在浏览器中完美运行一样。难道是因为它是一个ip而不是一个域名?

更新我们已经设置了域名,但它仍然无法正常工作,所以这里有一个可以在浏览器中使用的链接,但不适用于 SDWebImage 或 AFNetworking:http: //communication.notitlabs.co/uploads/511db303367885c248000015/avatar.png

4

2 回答 2

3

如果您确实遇到 HTTP 错误 406,请在此处阅读- 听起来像是 HTTP 标头的问题。

不过,可以肯定的是,您需要查看 NSError 对象的code属性并将其与Foundations Constants Reference中的以下错误代码之一匹配:

   NSURLErrorUnknown = -1,
   NSURLErrorCancelled = -999,
   NSURLErrorBadURL = -1000,
   NSURLErrorTimedOut = -1001,
   NSURLErrorUnsupportedURL = -1002,
   NSURLErrorCannotFindHost = -1003,
   NSURLErrorCannotConnectToHost = -1004,
   NSURLErrorDataLengthExceedsMaximum = -1103,
   NSURLErrorNetworkConnectionLost = -1005,
   NSURLErrorDNSLookupFailed = -1006,
   NSURLErrorHTTPTooManyRedirects = -1007,
   NSURLErrorResourceUnavailable = -1008,
   NSURLErrorNotConnectedToInternet = -1009,
   NSURLErrorRedirectToNonExistentLocation = -1010,
   NSURLErrorBadServerResponse = -1011,
   NSURLErrorUserCancelledAuthentication = -1012,
   NSURLErrorUserAuthenticationRequired = -1013,
   NSURLErrorZeroByteResource = -1014,
   NSURLErrorCannotDecodeRawData = -1015,
   NSURLErrorCannotDecodeContentData = -1016,
   NSURLErrorCannotParseResponse = -1017,
   NSURLErrorInternationalRoamingOff = -1018,
   NSURLErrorCallIsActive = -1019,
   NSURLErrorDataNotAllowed = -1020,
   NSURLErrorRequestBodyStreamExhausted = -1021,
   NSURLErrorFileDoesNotExist = -1100,
   NSURLErrorFileIsDirectory = -1101,
   NSURLErrorNoPermissionsToReadFile = -1102,
   NSURLErrorSecureConnectionFailed = -1200,
   NSURLErrorServerCertificateHasBadDate = -1201,
   NSURLErrorServerCertificateUntrusted = -1202,
   NSURLErrorServerCertificateHasUnknownRoot = -1203,
   NSURLErrorServerCertificateNotYetValid = -1204,
   NSURLErrorClientCertificateRejected = -1205,
   NSURLErrorClientCertificateRequired = -1206,
   NSURLErrorCannotLoadFromNetwork = -2000,
   NSURLErrorCannotCreateFile = -3000,
   NSURLErrorCannotOpenFile = -3001,
   NSURLErrorCannotCloseFile = -3002,
   NSURLErrorCannotWriteToFile = -3003,
   NSURLErrorCannotRemoveFile = -3004,
   NSURLErrorCannotMoveFile = -3005,
   NSURLErrorDownloadDecodingFailedMidStream = -3006,
   NSURLErrorDownloadDecodingFailedToComplete = -3007
于 2013-02-14T19:10:45.950 回答
0

只需在等之前调用此代码.sd_setImage

SDWebImageDownloader.shared().setValue("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", forHTTPHeaderField: "Accept")

不能确定,但​​这看起来像 SDWebImage 中的错误?这有点奇怪,因为相同的代码适用于一个域/路径,但不适用于另一个......

于 2018-06-29T00:53:08.517 回答