AFNetworking上传之后回调慢

在使用AFNetworking框架的时候,打印上传进度和回调,发现上传进度已经100%了,但是等了半天才回调,调用回调函数。

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
    
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:kJLXUrlCompleteRequest(urlStr) parameters:[[NSMutableDictionary alloc] initWithDictionary:dic] constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
       for (int i=0; i<fromDatas.count; i++) {
            JLXNetToolMultipartFormData *form = [fromDatas objectAtIndex:i];
            [formData appendPartWithFileURL:[NSURL fileURLWithPath:form.filePath] name:form.postKey fileName:form.fileName mimeType:[form getMimeTypeStr] error:nil];
        }
    } error:nil];
    [request setValue:[[JLXCommonTools sharedJLXCommonTools] getHttpHeaderStr] forHTTPHeaderField:@"ua"];
    NSURLSessionUploadTask * uploadTask = [manager
                                           uploadTaskWithStreamedRequest:request
                                           progress:^(NSProgress * _Nonnull uploadProgress) {
                                               dispatch_async(dispatch_get_main_queue(), ^{
                                                   NSLog(@"%f",uploadProgress.fractionCompleted);
                                               });
                                           }
                                           completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
                                               if (self.errorUpCompletionHandler) {
                                                   self.errorUpCompletionHandler(response, responseObject, error);
                                               }
                                           }];
    [uploadTask resume];

用的阿里云的服务器,然后让服务端查询,服务端查询从接受数据到返回居然需要6s,最后发现阿里云的上传有一个外网接口和一个内网接口,他们服务端之前用的是外网接口传的数据,然后改为内网接口之后,再测试,恢复正常,只需1s即可。

Last modification:April 20th, 2017 at 11:25 pm
如果看了这个文章可以让你少加会班,可以请我喝杯可乐
已打赏名单
微信公众号

Leave a Comment