2012-05-25 35 views
3

好吧我一直在调试整个一天,但无法弄清楚我的代码有什么问题。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

打印出错描述可能会有帮助。 'NSLog(@“didFailWithError:%@”,错误);' – Kreiri

+0

@Kreiri用新的日志输出更新了我的帖子 –

回答

1

也许当你登录时,API的行为会有所不同。从你的日志消息看来,它返回的是text/html内容,而不是RestKit知道如何处理的东西。

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