2012-01-19 87 views
1

我遇到了iOS/Restkit應用程序的問題。它以前工作正常,但現在不再。當然,我已經搗毀了一百萬件,但我認爲沒有什麼意義。問題是我可以通過curl從終端與我的服務器通信,但是當我從我的應用程序嘗試時,我的服務器會引發異常!我在做什麼錯誤的RestKit?服務器給出了從iOS/Restkit不同於curl的響應

首先我們看到我已經刪除了我的帳戶,並從終端創建了一個新帳戶。 (我也去了,又被刪除,它只是讓我可以嘗試,並從我的應用程序創建它。)(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 = @"[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]); 
} 

而當我運行這個我得到這個響應。首先,從跟蹤:(我已經刪除了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":"[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. 

然後我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應用程序如何從curl獲得不同的響應?我有服務器的控制權,所以我不認爲它是響應用戶代理。謝謝!

回答

2

您將RestKit配置爲POST JSON,但是您使用curl來POST表單編碼的參數。您需要更改RestKit序列化MIME類型。

+0

就是這樣,謝謝! objectManager.serializationMIMEType = RKMIMETypeFormURLEncoded; 我已經在那段代碼中工作了一段時間,回到我的應用程序的其他部分...忘記了這個變化。 –

相關問題