I am attempting to call api.php on my local server(using MAMP). The server side api.php is being called but the content of _POST inside the php code contains the following error:
Error Domain = NSCocoaErrorDomain Code = 3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo = 0x15d7bdd0 {NSDebugDescription = JSON text did not start with array or object and option to allow fragments not set.}
My app that is trying to send the JSON POST request to the api.php is an iOS app using AFNetworking 2
This is my request code:
- (void)postUpdateRequest
{
if (!dataModel)
dataModel = [[DataModel alloc] init];
NSDictionary *params = @{@"foo": @"bar2"};
NSLog(@"%@",params);
/* NSDictionary *params = @{@"cmd":@"update",
@"user_id":[dataModel userId],
@"token":[dataModel deviceToken]
};//@"ip_address":[dataModel getIPAddress]};*/
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager POST:ServerApiURL parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
I looked all over the internet but can't find an answer for my specific problem. No matter what I do I get the same error back.
Why is my JSON not properly formatted? I also can't seem to find a way to sniff what JSON I am actually sending.
Thank you.