当收到302 AWS的S3 NSURLSessionDownloadTask被取消:AFNetworking 2.0AWS、AFNetworking、NSURLSessionDownloadTask

2023-09-11 09:35:21 作者:住在白日梦里的小情人

我使用的README文件(从AFNetworking 2.0页)一个简单的例子来下载图像。一切工作正常的图像提供直接从我的网站,断绝。 但是,对于那些位于S3的web服务器返回302重定向以下错误:

I'm using a simple example from the README file (from AFNetworking 2.0 page) to download an image. All works fine for the images served directly from my web-sever. But for those located on the S3 the web-server returns 302 Redirect the following error:

Error Domain=NSURLErrorDomain Code=-999 "cancelled"

当我试图从S3下载图像(使用相同的code)直接(忽略重定向)我收到同样的错误。

When I try to download the image (using the same code) directly from the S3 (omitting the redirection) I receive the same error.

我已经检查了wget的实际图像的可用性。该图像是公开可用( https://youguide.s3.amazonaws.com/icons/user_96x96巴纽)。

I've checked the availability of the actual image with wget. The image is publicly available (https://m.xsw88.com/allimgs/daicuo/20230911/3671.png).

任何人都遇到类似的问题?

Anyone experience the similar problem?

推荐答案

我有同样的问题与S3,似乎已经解决了。 AFNetworking是在被取消请求认证挑战处理逻辑返回一个值

I was having the same problem with S3 and seem to have resolved it. AFNetworking was returning a value in the authentication challenge handling logic that was canceling the request.

通过告诉 AFURLSessionManager 如何处理我已经解决了这一问题验证挑战。

By telling the AFURLSessionManager how to handle authentication challenges I've fixed the problem.

[manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
    return NSURLSessionAuthChallengePerformDefaultHandling;
}];