I want to create a user to a back-end server, I need to enter following information to register user.
{
"user": {
"email": "[email protected]",
"password": "secret",
"password_confirmation": "secret",
"seed_recipes": true //optional
}
I wrote following code for registering a user:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSDictionary *parameters = @{@"user[email]":email, @"user[password]":password, @"user[password_confirmation]":password};
[manager POST:@"http://domain.com" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
I got following errors. Does any body know the reason? (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7fbe935cb360 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set., NSUnderlyingError=0x7fbe935c54b0 "Request failed: unauthorized (401)"}
Probably your server doesn't respond as JSON format just pure HTML.
Try adding:
If that doesn't help, make sure your server responds in JSON format to POST you are trying to make.