Reputation: 4173
I'm trying to send some information from my app to my PHP server side program.
When I try to send the same data using the PHP Array
as UnitTest it works. So I dont know why AFNeworking is thinking that this doesnt work.
In order to debug the problem i need to be able to see the full HTTP message.
How could I see the plain(NON-JSON) error (the HTTP response)?
I though that operation.JSONReadingOptions = NSJSONReadingAllowFragments;
would do the trick, but is not working or i am not placing it in the right place
Thanks
My error:
2013-06-05 10:52:37.990 iGym[9407:c07]Request failed with error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x96db4d0 {NSDebugDescription=Garbage at end.}, {
NSDebugDescription = "Garbage at end.";
}
My Objective-c code
User* myUser = [self getCurrentUser];
NSURL *url = [[NSURL alloc]initWithString:@"http://192.168.1.64/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];
NSDictionary *params = @{@"register":@"true",
@"email":@"as234d",
@"userID":(myUser.idUserExternal ? myUser.idUserExternal: @"NO"),
@"userDetails":@{@"needUsername":(myUser.nickname ? @"NO": @"YES"),
@"username":( myUser.nickname ? myUser.nickname : _input.text),
@"language":(myUser.language? myUser.language: @"0"),
@"name":(myUser.name ? myUser.name : @"0"),
@"surname":(myUser.surname ? myUser.surname : @"0"),
@"country":(myUser.country ? myUser.country : @"0"),
@"dob":(myUser.dob ? myUser.dob : @"0"),
@"city":(myUser.city ? myUser.city : @"0"),
@"height":(myUser.height ? myUser.height : @"0"),
@"weight":(myUser.weight ? myUser.weight : @"0"),
@"metricType":(myUser.metricSystem ? myUser.metricSystem : @"0")
}
};
NSLog(@"%@",params);
NSURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"igym/bootstrap.php" parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
NSLog(@"Inside the success block %@",JSON);
if ([JSON objectForKey:@"ok"]) {
[self done:JSON];
}
if ([JSON objectForKey:@"error"]) {
[self tryAgain:JSON[@"error"]];
}
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
NSLog(@"json text is: %@", JSON);
NSLog(@"Request failed with error: %@, %@", error, error.userInfo);
}];
operation.JSONReadingOptions = NSJSONReadingAllowFragments;
[operation start];
Upvotes: 1
Views: 2703
Reputation: 19544
In your success
or error
block, you can NSLog
operation.responseString
or operation.responseData
. That will give you the raw string or bytes sent from the server.
Upvotes: 9