Hey
I am struggling with making a POST request to parse a REST API. I am using AFNetworking 2.0. My code for a subclass of AFHTTPSessionManager is as follows:
+ (ParseAPISession *)sharedSession { static ParseAPISession *sharedSession = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedSession = [[ParseAPISession alloc] initWithBaseURL:[NSURL URLWithString:kSDFParseAPIBaseURLString]]; }); return sharedSession; }
and
- (id)initWithBaseURL:(NSURL *)url { self = [super initWithBaseURL:url]; if (self) { [self.requestSerializer setValue:kSDFParseAPIApplicationId forHTTPHeaderField:@"X-Parse-Application-Id"]; [self.requestSerializer setValue:kSDFParseAPIKey forHTTPHeaderField:@"X-Parse-REST-API-Key"]; } return self; }
I am making a request as follows:
[[ParseAPISession sharedSession] POST:@"ClassName" parameters: [NSDictionary dictionaryWithObjectsAndKeys:@"name", @"name", nil] success:^(NSURLSessionDataTask *task, id abc) { NSLog(@"%@", abc); } failure:^(NSURLSessionDataTask *task, NSError *error) { NSLog(@"%@", error); }];
When doing this, I always get this error:
Domain error = NSCocoaErrorDomain Code = 3840 "Operation could not be performed. (Cocoa error 3840.)" (JSON text did not start from the array or object, and the option allowed the removal of fragments.) UserInfo = 0x8c72420 {NSDebugDescription = JSON text did not start from the array or object and options to allow fragments.}
Since the GET request works like a charm, I am completely confused why I cannot do something POST. Can someone stop me with this problem?
Yours faithfully!
UPDATE
Fortunately, after repeated testing, this error message no longer appears, unfortunately, another did not appear:
<NSHTTPURLResponse: 0x8b96d40> { URL: https://api.parse.com/1/users } { status code: 400, headers { "Access-Control-Allow-Origin" = "*"; "Access-Control-Request-Method" = "*"; "Cache-Control" = "no-cache"; Connection = "keep-alive"; "Content-Length" = 130; "Content-Type" = "application/json; charset=utf-8"; Date = "Wed, 30 Oct 2013 20:01:58 GMT"; Server = "nginx/1.4.2"; "Set-Cookie" = "_parse_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlNjIxZjUxMzY3NWVhZWJmMDYyYWYwMGJiZTQ3MThmMWE%3D--851bd31b07e7dba2c5f83bb13a8d801ecbea42c4; domain=.parse.com; path=/; expires=Fri, 29-Nov-2013 20:01:58 GMT; secure; HttpOnly"; Status = "400 Bad Request"; "X-Runtime" = "0.060910"; "X-UA-Compatible" = "IE=Edge,chrome=1"; } } = BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlNjIxZjUxMzY3NWVhZWJmMDYyYWYwMGJiZTQ3MThmMWE% 3D - 851bd31b07e7dba2c5f83bb13a8d801ecbea42c4; domain = .parse.com; path = /; expires = Fri, <NSHTTPURLResponse: 0x8b96d40> { URL: https://api.parse.com/1/users } { status code: 400, headers { "Access-Control-Allow-Origin" = "*"; "Access-Control-Request-Method" = "*"; "Cache-Control" = "no-cache"; Connection = "keep-alive"; "Content-Length" = 130; "Content-Type" = "application/json; charset=utf-8"; Date = "Wed, 30 Oct 2013 20:01:58 GMT"; Server = "nginx/1.4.2"; "Set-Cookie" = "_parse_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlNjIxZjUxMzY3NWVhZWJmMDYyYWYwMGJiZTQ3MThmMWE%3D--851bd31b07e7dba2c5f83bb13a8d801ecbea42c4; domain=.parse.com; path=/; expires=Fri, 29-Nov-2013 20:01:58 GMT; secure; HttpOnly"; Status = "400 Bad Request"; "X-Runtime" = "0.060910"; "X-UA-Compatible" = "IE=Edge,chrome=1"; } }
Can someone tell me what status will tell me: 400 Bad Request and how can I get rid of it?