Reputation: 20150
I'm trying to use AFNetworking to call a Rest API but I'm not getting the proper response string. This is my code:
NSURL *url = [[NSURL alloc] initWithString:@"https://www.ez-point.com/api/v1/ezpoints"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"%@",@"testing");
NSLog(@"%@",operation.responseData);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"%@", @"Error");
}];
[operation start];
but I'm getting this as print out:
2013-10-29 08:31:08.175 EZ-POINT[4004:c07] testing
2013-10-29 08:31:08.175 EZ-POINT[4004:c07] (null)
As you can see, it is returning null, I was expecting this:
{"status": "user_invalid", "data": "", "token": "", "errors": ["user not found"], "user_id": ""}
Upvotes: 0
Views: 262
Reputation: 11073
I'm more accustomed to this way of setting up the request:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.ez-point.com/api/v1/ezpoints"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"%@",@"testing");
NSLog(@"%@",operation.responseData);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"%@", @"Error");
}];
[operation start];
Upvotes: 1