I'm new using AFNetworking and there is something I'm missing calling an API.
Here is the code (most of part the AF* example) :
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy.allowInvalidCertificates = YES;
AFJSONRequestSerializer *reqSerializer = [AFJSONRequestSerializer serializer];
[reqSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[reqSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
manager.requestSerializer = reqSerializer;
AFJSONResponseSerializer *resSerializer = [AFJSONResponseSerializer serializer];
[resSerializer setReadingOptions:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers];
resSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json", nil];
manager.responseSerializer = resSerializer;
NSString *URLString =[NSString stringWithFormat:@"%@/users/userLogin", BaseURLString];
NSDictionary *params = @{
@"userName": self.txtUser.text,
@"passWord": self.txtPass.text
};
[manager POST:URLString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
Calling the code as is the URL is: http://localhost:8000/users/userLogin
BUT with right parameters should be: http://localhost:8000/users/userLogin/JOHN/MYPASS
Finally i'm getting "Request failed: not found (404)"
The dirty workaround to test AFNetworking:
NSString *URLString = [NSString stringWithFormat:@"%@/users/userLogin/%@/%@", BaseURLString, self.txtUser.text, self.txtPass.text];
And it worked :p
Any idea what is wrong ?
Thank you for the help !