iphone - RestKit 请求似乎只工作一次

标签 iphone ios ios5 restkit

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

目标是使用 RestKit 将 POST 发送到 Heroku API,其中包含用户名/密码以检索 API key 。

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

我正在使用当前版本的 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.)"

谁能帮我解释为什么会出现这种行为?

最佳答案

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

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

关于iphone - RestKit 请求似乎只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10754772/

相关文章:

iphone - 禁用以肖像 AVFoundation 以外的任何方向拍摄图像

iphone - Xcode 在您的钥匙串(keychain)中找不到此配置文件的有效私有(private)证书/有效 key 对

ios - 适用于 iOS 目标的 Ada 交叉编译器

ios - 提交我的应用程序后,iAds 停止工作

ios - 带有GL_DEPTH_COMPONENT的glTexImage2D在iOS4上可运行,在iOS 5上无法运行GL_INVALID_ENUM

c++ - 链接静态 C++ 库时 Objective-C 中的损坏符号表

iphone - 我如何在 ViewController 中使用 appDelegate 中声明的字符串?

ios - 检测所有按钮的单一控制事件

ios5 - iOS6 中的 CollapsableTableView、UIViewControllerHierarchyInconsistency 错误

IOS 5 无法识别的选择器在 setBackgroundImage 的外观代理处发送