AFNetworking 2.0: NSURLSessionDownloadTask is cancelled when received 302 to AWS S3

旧巷老猫 提交于 2020-01-13 05:23:47

问题


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"

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

I've checked the availability of the actual image with wget. The image is publicly available (https://youguide.s3.amazonaws.com/icons/user_96x96.png).

Anyone experience the similar problem?


回答1:


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.

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;
}];


来源:https://stackoverflow.com/questions/19179344/afnetworking-2-0-nsurlsessiondownloadtask-is-cancelled-when-received-302-to-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!