2013-01-07 29 views
2

我有一個restkit函數,我調用webservice來檢查我的登錄憑證。在這個電話中,我給我的電子郵件和密碼作爲參數。在這裏你可以看到代碼。Restkit Post總是進入失敗部分

RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://****.com/nl/webservice/"]]; 


NSDictionary *dictionary = [[NSDictionary alloc]initWithObjectsAndKeys:_txtLogin.text,@"email",_txtPass.text,@"pwd", nil]; 
     NSLog(@"till here"); 
NSMutableURLRequest *request = [manager requestWithObject:nil method:RKRequestMethodPOST path:@"company-user/login/apikey/key*****?" parameters:dictionary]; 
     NSLog(@"till here2"); 
RKObjectRequestOperation *operation = [manager objectRequestOperationWithRequest:request success:^(RKObjectRequestOperation *operation, RKMappingResult *result) { 
    NSLog(@"till here3"); 
    NSLog(@"Loading mapping result: %@", result); 
}failure:^(RKObjectRequestOperation *operation, NSError *error){ 
    //Failure 
    NSLog(@"error is:%@ ",error); 
    NSLog(@"FAILUREE!"); 
}]; 

     NSLog(@"till here4"); 
[operation start]; 
     NSLog(@"till here5"); 

但由於某種原因,我去了失敗的一部分。它首先給我一個狀態200回來,但然後一個錯誤。你可以在這裏看到我的日誌。

2013-01-07 20:33:45.858 Offitel2[26195:c07] till here 
2013-01-07 20:33:45.859 Offitel2[26195:c07] till here2 
2013-01-07 20:33:45.860 Offitel2[26195:c07] till here4 
2013-01-07 20:33:47.252 Offitel2[26195:c07] till here5 
2013-01-07 20:33:47.254 Offitel2[26195:c07] I restkit.network:RKHTTPRequestOperation.m:152 POST 'http://virtuele-receptie.preview.sanmax.be/nl/webservice/company-user/login/apikey/key12345678?' 
2013-01-07 20:33:47.255 Offitel2[26195:c07] I restkit.network:RKHTTPRequestOperation.m:179 POST 'http://virtuele-receptie.preview.sanmax.be/nl/webservice/company-user/login/apikey/key12345678?' (200 OK) [0.0005 s] 
2013-01-07 20:33:47.255 Offitel2[26195:c07] error is:Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0xa869130 {NSErrorFailingURLStringKey=http://virtuele-receptie.preview.sanmax.be/nl/webservice/company-user/login/apikey/key12345678?, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://virtuele-receptie.preview.sanmax.be/nl/webservice/company-user/login/apikey/key12345678?', which failed to match all (0) response descriptors:, NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://virtuele-receptie.preview.sanmax.be/nl/webservice/company-user/login/apikey/key12345678?, NSUnderlyingError=0xa8695b0 "No mappable object representations were found at the key paths searched."} 
2013-01-07 20:33:47.256 Offitel2[26195:c07] FAILUREE! 

有人能幫助我嗎?如果您希望執行的響應打電話web服務,你必須提供響應描述的對象映射

親切的問候

回答

0

我問我同樣的事情,「是不是我可以只讀json文件?沒有對象映射?」,我發現的解決方案是RestKit 0.20使用AFNetworking。因此,如果您需要在沒有映射的情況下發出請求,請執行下一步。

[AFNetworkActivityIndicatorManager sharedManager].enabled = YES; 

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://****.com/nl/webservice/"]]; 
NSDictionary *params  = [NSDictionary dictionaryWithObjectsAndKeys: 
          _txtLogin.text, @"email", 
          _txtPass.text, @"pwd", 
          nil]; 
[httpClient postPath:@"company-user/login/apikey/key*****?" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    NSData *jsonData = [operation.responseString dataUsingEncoding:NSUTF8StringEncoding]; 
    NSError *error = nil; 

    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData: jsonData 
                   options: NSJSONReadingMutableContainers 
                    error: &error]; 
    NSLog(@"%@", jsonDict); 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    NSLog(@"[HTTPClient Error]: %@", error.localizedDescription); 
}];