【问题标题】:Restkit Post always goes in the failure partRestkit Post 总是进入失败部分
【发布时间】:2013-01-07 19:29:18
【问题描述】:

我有一个 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!

有人可以帮我吗?

亲切的问候

【问题讨论】:

    标签: objective-c ios web-services post restkit


    【解决方案1】:

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

    【讨论】:

    • 是不是只能读取json文件?没有对象映射?
    【解决方案2】:

    我也在问同样的问题,“难道我不能只读取 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);
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多