ios - 域=NSURLError域代码=-1021 "request body stream exhausted"

标签 ios afnetworking

我收到 NSURLErrorDomain Code=-1021“请求正文流耗尽”

NSLocalizedDescription=请求体流耗尽,NSUnderlyingError=0x2088c080“请求体流耗尽”

上传多张大尺寸图片时出现此错误 我正在使用 AFNetworking 并尝试在线搜索修复程序,但未成功

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


                                        }
                                    }

                                }];

最佳答案

AFNetworking FAQ 中所述:

Why are some upload requests failing with the error "request body stream exhausted"? What does that mean, and how do I fix this?

When uploading over a 3G or EDGE connection, requests may fail with "request body stream exhausted". Using -throttleBandwidthWithPacketSize:delay: your multipart form construction block, you can set a maximum packet size and delay according to the recommended values (kAFUploadStream3GSuggestedPacketSize and kAFUploadStream3GSuggestedDelay). This lowers the risk of the input stream exceeding its allocated bandwidth. Unfortunately, as of iOS 6, there is no definite way to distinguish between a 3G, EDGE, or LTE connection. As such, it is not recommended that you throttle bandwidth based solely on network reachability. Instead, you should consider checking for the "request body stream exhausted" in a failure block, and then retrying the request with throttled bandwidth.

关于ios - 域=NSURLError域代码=-1021 "request body stream exhausted",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16068158/

相关文章:

ios - 如何使用 NSBundle loadNibNamed :? 加载多个 nib 文件

ios - dispatch_barrier_async 不等待 CoreImage 完成处理

objective-c - 如何从 iOS 中的 URL 获取图像大小

ios - AFNetworking 从错误端点获取响应 JSON

ios - AFNetworking 2.0 上的缓存

ios - 如何同时管理来自两个不同 Controller 的两个 AFNetworking 操作

ios - 如何将变量设置为从 0 开始并通过嵌套 for 循环 Swift 2 中的每个循环获得一个级别

ios - 如何在 Swift 项目中添加微信 API?

ios - SVG 动画的 'onbegin' 事件未在 IOS 上触发

ios - 如何发送所有 AFNetworking 请求的通用信息?