2

我有一个 restkit 函数,我调用一个 web 服务来检查我的登录凭据。在这次通话中,我将我的电子邮件和密码作为参数。在这里你可以看到代码。

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!

有人可以帮我吗?

亲切的问候

4

2 回答 2

0

如果您希望对调用 Web 服务的响应执行对象映射,则必须提供响应描述符。请查看https://github.com/RestKit/RestKit/wiki/Object-Mapping以获取说明和示例。

于 2013-01-07T22:28:19.337 回答
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);
}];
于 2013-07-25T20:45:39.843 回答