我收到 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
andkAFUploadStream3GSuggestedDelay
). 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/