请求正文流已耗尽

请求正文流已耗尽

本文介绍了域= 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 imagesI 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 = @"https://mydomain.zendesk.com/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代码= -1021“请求正文流已耗尽”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 02:23