【问题标题】:Client closed connection before receiving entire response AFNetworking客户端在收到整个响应之前关闭连接 AFNetworking
【发布时间】:2015-11-09 11:47:06
【问题描述】:

无法下载文件 收到此错误“客户端在收到整个响应之前关闭连接” 我要下载的文件只有 266KB

     for (NSString *downloadURL in arr) {
   // NSString *downloadURL = [d objectForKey:@"url"];
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"URL for downloading : %@",downloadURL);
        NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
        NSString *documentsDirectory = [pathArray objectAtIndex:0];
        NSString *downloadedZipPath = [documentsDirectory stringByAppendingPathComponent:TEMP_DICTIONARY];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:downloadURL]];
       // [request addValue:@"bytes=x-" forHTTPHeaderField:@"Range"];
       // [request setTimeoutInterval:20];
        AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

        operation.outputStream = [NSOutputStream outputStreamToFileAtPath:downloadedZipPath append:NO];

        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"Success");
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
        }];

        [operation start];
    });

试图增加 api 请求超时但仍然无法正常工作

【问题讨论】:

    标签: ios objective-c afnetworking afnetworking-2


    【解决方案1】:

    尝试将其设置为更多时间

    [request setTimeoutInterval:20];
    

    【讨论】:

      【解决方案2】:

      我有一些这样的错误。但我认为这不是 AF 故障。当您请求的事物的内容类型与其原始内容类型不同时,将出现此错误。 例如:
      当您请求 mp4 文件时,服务器应将 content-type 设置为 video/mpeg4,或者您可以将请求类型从 GET 更改为 POST。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-22
        • 2017-01-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-10
        • 2016-09-09
        相关资源
        最近更新 更多