3

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

目标是使用用户名/密码将带有 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];
}

日志

/// ---> 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.)"

谁能帮我解释为什么会发生这种行为?

4

1 回答 1

1

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

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

于 2012-05-25T13:40:04.943 回答