title: AFNetworking + download file OR JSON response + setDownloadProgressBlock
body: <p>I have a problem to download a file or manage an error in some cases (JSON)</p>
  
  <p>The download works very fine. The problem is the server can send a 404 or 200 (with JSON) in a few cases when the user requests the download.</p>
  
  <p>How to handle the JSON in this case? When we send the request we don't know if we will receive JSON error (with a 200 status oR 404) or the zipped file...</p>
  
  <p>I don't see how responseObject can help me.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>  AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
    operation.outputStream = [NSOutputStream outputStreamToFileAtPath:zipPath append:NO];
  
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) 
    {
      NSLog(@"Successfully downloaded zip file to %@", zipPath);
  
      // is-it impossible to handle a JSON response here ?
      // responseObject can help me ? don't think !
  
      // do what I have to do after the download is complete
    } 
    failure:^(AFHTTPRequestOperation *operation, NSError *error) 
    {
      // 404
      // is-it impossible to handle a JSON response here ?
      if ([error code] == -1011)
      {
  
      }
    }];
  
    [operation setDownloadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
      float progress = ((float)((int)totalBytesWritten) / (float)((int)totalBytesExpectedToWrite));
      self.progressView.progress = progress;
    }];  
    [operation start];
  </code></pre>
  
  <p>Does I need to make a AFJSOnRequestOperation ? But in this case, how to receive the downloaded file that is not JSON ?
  Thanks for helping.</p>
  
  <p>EDIT: as I wroted in my comments, I can get and catch the responseData in success block ONLY if I comment the line:</p>
  
  <pre><code> operation.outputStream = [NSOutputStream outputStreamToFileAtPath:zipPath append:NO];
  </code></pre>
  
  <p>It's logical, I suppose the response goes into outputStream instead of success block. Is there a solution for that ?</p>