我的iOS / Restkit应用程序出现问题。它过去工作正常,但现在不再。当然,我已经找到了一百万件事,但我认为没有什么是重要的。问题是我可以通过curl从终端与我的服务器进行良好的通信,但是当我从我的应用程序尝试时,我的服务器会抛出异常!我在RestKit上做错了什么?
首先我们看到我删除了我的帐户并从终端创建了一个新帐户。 (我也去了并再次将其删除,以便我可以尝试从我的应用程序创建它。)(IP地址被删除。)
$ 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
一切都按预期进行。所以这是我的应用程序代码:
{
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
objectManager.serializationMIMEType = RKMIMETypeJSON;
[CreateAccount setupCreateAccountMapping];
CreateAccount* user = [[CreateAccount alloc] init];
user.email = @"paul@longpointlabs.com";
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]);
}
当我跑这个时,我得到了这个回应。首先,从跟踪:(我已删除IP地址......)
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":"paul@longpointlabs.com"}.
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.
然后我的didLoadResponse:
2012-01-19 14:07:22.850 test[2750:fb03] didLoadResponse: javax.transaction.RollbackException: ARJUNA-16053 Could not commit transaction.
然后,奇怪的是,didFailWithError也被称为:
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.
我对此感到困惑,我的iOS应用程序如何从卷曲中获得不同的响应?我控制了服务器,所以我认为它不响应User-Agent。谢谢!
答案 0 :(得分:2)
您已将RestKit配置为POST JSON,但您正在使用curl来POST表单编码的参数。您需要更改RestKit序列化MIME类型。