title: (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.)
body: <p>I find this error to happen to many other users and although trying many of suggested solutions nothing seems to work, so I'm trying to post my specific case.</p>
  
  <p>I'm trying to save an image from iphone application to my postgresql database using django.</p>
  
  <p>my view looks like this:</p>
  
  <pre><code>def objectimages(request, obj_id):
      object = imagesTable.objects.filter(uniqueid=obj_id)
      if request.method == 'POST':
          value = request.POST.get('image')
          f= open('image.txt', 'w+')
          f.write(value)
          f.close()
          object.update(image=value)
          return HttpResponse("Post received")
      elif request.method == 'GET':
          output = serializers.serialize('json',object, fields=('image'),indent=5, use_natural_keys=True)
          return HttpResponse(output, content_type="application/json")
  </code></pre>
  
  <ul>
  <li>the file is just for debug purposes and it seems to write the correct data</li>
  <li>also tried return HttpResponse({}, content_type="application/json")</li>
  </ul>
  
  <p>in my application the post request is done using AFNetworking like this:</p>
  
  <pre><code>-(void) saveImageToDB
  {
      NSString* BaseURLString = POST_IMAGE;
  
      NSData* data = UIImagePNGRepresentation(self.image);
  
  
      AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  
      [manager POST:BaseURLString
         parameters:@{@"image":[data base64EncodedString]}
           success:^(AFHTTPRequestOperation *operation, id responseObject) {
               NSLog(@"image saved successfuly");
           }
           failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              NSLog(@"Error saving image: %@", error)
  
           }];
  }
  </code></pre>
  
  <p>so I added this line of code</p>
  
  <pre><code>manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
  </code></pre>
  
  <p>and got this error: <code>Invalid value around character 1</code></p>
  
  <p>I also try to do:</p>
  
  <pre><code>AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
  
  [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  [requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  
  manager.requestSerializer = requestSerializer;
  </code></pre>
  
  <p>which ended up always with <code>The request timed out.</code></p>
  
  <p>please advice what is wrong with my request</p>