title: Request failed: unacceptable content-type: image/jpg using AFNetworking 2.5
body: <p>I know this question has already been asked several times in stack overflow. But I am still quite confusing about it. I tried use </p>
  
  <pre><code>manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"image/jpg", nil];
  </code></pre>
  
  <p>But I still got the error until I added header("Content-type:application/json"); in my php file. But there is no jason struct in my php file. </p>
  
  <p>My ios side is:</p>
  
  <pre><code>AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
  
  NSError *__autoreleasing* error;
  // 2. Create an `NSMutableURLRequest`.
  NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:@"http://192.168.199.118/search.php" parameters:nil constructingBodyWithBlock:^(id&lt;AFMultipartFormData&gt; formData) {
      [formData appendPartWithFileData:imageData
                                  name:@"uploadedfile"
                              fileName:@"image.jpg"
                              mimeType:@"image/jpg"];
  } error:(NSError *__autoreleasing *)error];
  
  AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  manager.responseSerializer = [AFHTTPResponseSerializer serializer];
  
  manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"image/jpg", nil];
  
  AFHTTPRequestOperation *operation =
  [manager HTTPRequestOperationWithRequest:request
                                   success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                       NSLog(@"Success %@", responseObject);
  
  
                                   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                       NSLog(@"Failure %@", error.description);
                                       if (error.code == -1001) {
                                           [self NetworkAlert:@"Resquest timed out. Please try again and check your network connection."];
  
                                       }
                                   }];
  </code></pre>
  
  <p>My php side is :</p>
  
  <pre><code>&lt;?php
  
  #function for streaming file to client
  function streamFile($location, $filename, $mimeType='image/jpg')
  { if(!file_exists($location))
    { header ("HTTP/1.0 404 Not Found");
      return;
    }
  
    //header("Content-Type: $mimeType"); 
    header("Content-type:application/json");
    readfile($location);
  
  }
  
  #**********************************************************
  #Main script
  #**********************************************************
  header("Content-type:application/json");
  #&lt;1&gt;set target path for storing photo uploads on the server
  $photo_upload_path = "upload/";
  $photo_upload_path = $photo_upload_path.basename( $_FILES['uploadedfile']['name']); 
  $photo_upload_indicator_path = "upload/image_ready";
  
  #&lt;2&gt;set target path for storing result on the server
  $downloadFileName = 'processed_';
  $processed_photo_output_path = "output/processed_";
  $processed_photo_output_path = $processed_photo_output_path.basename( $_FILES['uploadedfile']['name']); 
  $processed_photo_output_indicator_path = "output/result_ready";
  $downloadFileName = $downloadFileName.basename( $_FILES['uploadedfile']['name']); 
  
  #&lt;3&gt;modify maximum allowable file size to 10MB and timeout to 300s
  ini_set('upload_max_filesize', '10M');  
  ini_set('post_max_size', '10M');  
  ini_set('max_input_time', 300);  
  ini_set('max_execution_time', 300);  
  
  #&lt;4&gt;Get and stored uploaded photos on the server
  if(copy($_FILES['uploadedfile']['tmp_name'], $photo_upload_path)) {
  
      #&lt;5&gt;signal that the image is ready
      $handle = fopen($photo_upload_indicator_path, 'w');
      fprintf($handle, '%s', $photo_upload_path);
      fclose($handle);
  
      #&lt;6&gt;wait until the result is ready
      while (!file_exists($processed_photo_output_indicator_path))
      {
          usleep(1000000);
      }
      usleep(1000000);
      unlink($processed_photo_output_indicator_path);
  
      #&lt;7&gt;stream processed photo to the client
      streamFile($processed_photo_output_path, $downloadFileName,'image/jpg');
  } else{
      echo "There was an error uploading the file to $photo_upload_path !";
  }
  
  ?&gt;
  </code></pre>
  
  <p>The header("Content-type:application/json"); helps me solve the problem. But I don't know why.
  And if delete this code, I will always get the the "request failed error". And if I want to receive some info from the php server with the image, which way is the best? Thank you very much for any advise. </p>