1
I have a form that must be filled in the application and sent to the web service to register a new user.
How could I send this data to the web service using Afnetworking 2.0?
I tried to use the code below, but returned an error:
NSDictionary *params = @{@"id" : idCadastro.text,
@"nome" : nomeCadastro.text,
@"email" : emailCadastro.text,
@"cidade" : localidadeCadastro.text,
@"passe" : senhaCadastro.text
};
NSString* HOST_URL = @"http://10.1.1.6/advphp/cad_adv_0.php?";
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
[operationManager POST: HOST_URL parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject){
// Enter what happens here if successsful.
NSLog(@"Cadastrado");
}failure:^(AFHTTPRequestOperation *operation, NSError *error){
// Enter what happens here if failure happens
NSLog(@"Não Cadastrado. Erro:\n%@",error);
}
];
And below the error message that appears:
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=0x7969de10 {Nsdebugdescription=JSON text Did not start with array or Object and option to allow Fragments not set.}
Good Rafael got the following error:
Error Domain=NSCo coaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7babefa0 {NSDebugDescription=Invalid value around character 0.}
– Tiago Amaral
I think it might be the server, because in the PHP file called, I’m using $var = $_GET("id")... to receive the data. Could that be it?
– Tiago Amaral
Funny, the app gives this error but registers the data correctly in the database! But I need to solve this problem because I need the SUCCESS or FAILURE feature to call the next screen or go back to the previous one :/
– Tiago Amaral