Reputation: 8741
I'm having trouble with my iOS/Restkit app. It used to work fine but now no longer does. And of course, I've chaged a million things, but nothing that I think would be significant. The problem is that I can communicate with my server just fine from the terminal with curl, but when I try from my app my server throws an exception! What am I doing wrong with RestKit?
First we see I've deleted my account and created a new one from Terminal. (I also went and deleted it again just so I can try and create it from my app.) (IP addresses are removed.)
$ curl "http://0.0.0.0:8080/registration/rest/users/delete_account" -d "email=paul%40longpointlabs.com&pwd=123456&uname=Paul"
Success
$ curl "http://0.0.0.0:8080/registration/rest/users/create_account" -d "email=paul%40longpointlabs.com&pwd=123456&uname=Paul"
6345b3cedc5935b1dad9863c795c26391326998921644
$ curl "http://0.0.0.0:8080/registration/rest/users/delete_account" -d "email=paul%40longpointlabs.com&pwd=123456&uname=Paul"
Success
That all went as expected. So here's my app's code:
{
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.serializationMIMEType = RKMIMETypeJSON;
[CreateAccount setupCreateAccountMapping];
CreateAccount* user = [[CreateAccount alloc] init];
user.email = @"[email protected]";
user.uname = @"Paul";
user.pwd = @"123456";
[[RKObjectManager sharedManager] postObject:user delegate:self];
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error
{
RKResponse *response = [objectLoader response];
NSLog(@"didFailWithError Code: %d", [response statusCode] );
NSLog(@"didFailWithError Body: %@", [response bodyAsString] );
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse *)response
{
NSLog(@"idLoadResponse: %@", [response bodyAsString]);
}
And when I run this I get this response. First, from the tracing: (I've removed the IP address...)
2012-01-19 14:04:10.244 test[2703:fb03] T restkit.network:RKRequest.m:310 Prepared POST URLRequest '<NSMutableURLRequest http://0.0.0.0:8080/registration/rest/users/create_account>'. HTTP Headers: {
Accept = "application/json";
"Content-Length" = 64;
"Content-Type" = "application/json";
}. HTTP Body: {"pwd":"123456","uname":"Paul","email":"[email protected]"}.
2012-01-19 14:04:10.345 test[2703:fb03] D restkit.network:RKResponse.m:196 NSHTTPURLResponse Status Code: 406
2012-01-19 14:04:10.345 test[2703:fb03] D restkit.network:RKResponse.m:197 Headers: {
"Content-Length" = 79;
"Content-Type" = "application/json";
Date = "Thu, 19 Jan 2012 19:04:10 GMT";
Server = "Apache-Coyote/1.1";
}
2012-01-19 14:04:10.346 test[2703:fb03] T restkit.network:RKResponse.m:202 Read response body: javax.transaction.RollbackException: ARJUNA-16053 Could not commit transaction.
And then my didLoadResponse:
2012-01-19 14:07:22.850 test[2750:fb03] didLoadResponse: javax.transaction.RollbackException: ARJUNA-16053 Could not commit transaction.
And then, curiously, didFailWithError is also called:
2012-01-19 14:08:23.188 test[2750:fb03] didFailWithError Code: 406
2012-01-19 14:08:35.250 test[2750:fb03] didFailWithError Body: javax.transaction.RollbackException: ARJUNA-16053 Could not commit transaction.
I'm baffled at this, how can my iOS app get a different response back from curl? I have control of the server so I don't think it is responding to the User-Agent. Thanks!
Upvotes: 1
Views: 886
Reputation: 501
You have RestKit configured to POST JSON, but you're using curl to POST form-encoded params. You need to change your RestKit serialization MIME type.
Upvotes: 2