域= NSURLErrorDomain代码=

编程入门 行业动态 更新时间:2024-10-27 04:27:46
本文介绍了域= NSURLErrorDomain代码= -1021“请求正文流已耗尽”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在获取NSURLErrorDomain代码= -1021请求正文流已耗尽

I am getting the NSURLErrorDomain Code=-1021 "request body stream exhausted"

NSLocalizedDescription =请求正文流已耗尽,NSUnderlyingError = 0x2088c080请求正文流已耗尽}

NSLocalizedDescription=request body stream exhausted, NSUnderlyingError=0x2088c080 "request body stream exhausted"}

当我上传多个大尺寸图像时,我正在使用AFNetworking并尝试在线搜索修复程序,但未成功

This error is generated when uploading multiple big size images I am using AFNetworking and tried to search for a fix online, but didn't succeed

NSDictionary *clientUniqueId = [NSDictionary dictionaryWithObject:NSLocalizedString(uniqueDrId, nil) forKey:@"clientUniqueId"]; NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:pendingUpload.urlPath parameters:clientUniqueId constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFormData:[pendingUpload dataRecordData] name:@"dr"]; NSArray *attachments = pendingUpload.attachments; if (attachments != nil) { for (Attachment *attachment in attachments) { [formData appendPartWithFileData:attachment.data name:attachment.key fileName:attachment.filename mimeType:attachment.contentType]; } } }];

推荐答案

我也遇到了这个问题,并且没有 throttleBandwithWithPacketSize 方法的运气。我相信在我的情况下,这是一个身份验证挑战问题。

I was experiencing this issue also and didn't have any luck with the throttleBandwithWithPacketSize method. I believe in my case it was an authentication challenge issue.

我最后要做的是切换到AFNetworking 2.0中的URLSession连接方法,这似乎为我解决了这一问题。这是我最终使用的代码:

What I finally did was switch to the URLSession connection method in AFNetworking 2.0 and that seemed to solve it for me. Here is the code I ended up using:

NSString *uploadAttachmentURL = @"mydomain.zendesk/api/v2/uploads.json?filename=screenshot.jpeg"; NSData *imageData = UIImageJPEGRepresentation(image, 1.0); NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; _afHTTPSessionManager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration]; // hack to allow 'text/plain' content-type to work NSMutableSet *contentTypes = [NSMutableSet setWithSet:_AFOpManager.responseSerializer.acceptableContentTypes]; [contentTypes addObject:@"text/plain"]; _afHTTPSessionManager.responseSerializer.acceptableContentTypes = contentTypes; [_afHTTPSessionManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"[USERNAME]" password:@"[PASSWORD]"]; [_afHTTPSessionManager POST:uploadAttachmentURL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imageData name:@"screenshot" fileName:@"photo.jpg" mimeType:@"image/jpeg"]; } success:^(NSURLSessionDataTask *task, id responseObject) { DDLogError(@"screenshot operation success! %@", responseObject); } failure:^(NSURLSessionDataTask *task, NSError *error) { DDLogError(@"Operation Error: %@", error); }];

更多推荐

域= NSURLErrorDomain代码=

本文发布于:2023-11-26 05:42:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632857.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   NSURLErrorDomain

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!