RestKit请求似乎只能工作一次

时间:2012-05-25 12:50:41

标签: iphone ios ios5 restkit

好吧我整天都在调试,但无法弄清楚代码的问题。

目标是使用用户名/密码将具有RestKit的POST发送到Heroku API以检索API密钥。

问题是我只能发送一次请求。第二次发送错误时发送请求。 (所以我第一次将API键绑定到我的对象,但第二次只是一个错误)

我正在使用当前版本的RestKit(0.10)

代码:

- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
}
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObject:(id)object
{
    Account *account = (Account *)object;
    NSLog(@"API_KEY: %@", account.apiKey);
}

- (IBAction) login:(id)sender
{
    Account *account = [[Account alloc] init];
    account.email = [emailField text];
    account.password = [passwordField text];

    [[RKObjectManager sharedManager] postObject:account delegate:self];
}

LOG

/// ---> FIRST CLICK
2012-05-25 14:57:00.028 HerokuApp[11154:fb03] API_KEY: 1234567890
/// ---> SECOND CLICK
2012-05-25 14:57:03.427 HerokuApp[11154:fb03] W restkit.network:RKObjectLoader.m:281 Unable to find parser for MIME Type 'text/html'
2012-05-25 14:57:03.427 HerokuApp[11154:fb03] W restkit.network:RKObjectLoader.m:309 Encountered unexpected response with status code: 200 (MIME Type: text/html -> URL: https://api.heroku.com/login -- https://api.heroku.com -- https://api.heroku.com -- https://api.heroku.com)
2012-05-25 14:57:03.429 HerokuApp[11154:fb03] didFailWithError: Error Domain=org.restkit.RestKit.ErrorDomain Code=4 "The operation couldn’t be completed. (org.restkit.RestKit.ErrorDomain error 4.)"

有人可以帮我解释为什么会出现这种情况吗?

1 个答案:

答案 0 :(得分:1)

当您登录时,API可能会有不同的行为。从您的日志消息中,它似乎返回文本/ html内容,而不是RestKit知道如何处理的内容。

在Wireshark捕获数据包的机器上运行模拟器。重现错误,然后找到发生这种情况的TCP流并查看它。如果您需要帮助,请使用Wireshark中的“Follow Stream”结果更新您的问题,以便我们可以看到完整的HTTP流量。