Been using AFNetworking 2.0 for the past two projects for a medium sized project to great success.
This one call though, to post a user' login info, keep failing on me (server states incorrect login & password, login is the email, we've check on the server and the values are the same I'm trying to send)
The server developer does not handle iOS / ObjC (java / mongoDB guy), All I'm giving is a URL and the parameters I need to pass with Content-Type = application/x-www-form-url-encoded
I read somewhere that characters such as @ (in the email) could cause problems
Could anyone with more experience than me here chip in? my operation creation method is below, any help is TRULY appreciated.
-(AFHTTPRequestOperation *)loginUserWithParameters:(NSDictionary *)loginParameters
{
/*
parameters dictionary:
email
psw
deviceToken
*/
NSString *url=SERVER_USER_LOGIN;
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:url]];
// [httpClient setParameterEncoding:AFFormURLParameterEncoding];
NSMutableURLRequest *request=[httpClient requestWithMethod:@"POST" path:nil parameters:nil];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:loginParameters options:kNilOptions error:nil];
[request setHTTPBody:jsonData];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[AFNetworkActivityIndicatorManager sharedManager].enabled=YES;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
return operation;
}
Actually you say with your code that you will send url-encoded data to your server, but you are overriding the postBody of your request with custom data. So you should create your request with:
NSMutableURLRequest *request=[httpClient requestWithMethod:@"POST" path:nil parameters:loginParameters];
And you should delete below lines:
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:loginParameters options:kNilOptions error:nil];
[request setHTTPBody:jsonData];
I think above changes will be enough.