【问题标题】:iOS, RESTKit, How to set timeout for requestsiOS,RESTKit,如何为请求设置超时
【发布时间】:2014-08-05 07:44:43
【问题描述】:

我是 RESTKit 新手,我想为我的一些 REST 请求设置超时间隔。 This question 指的是同一个主题。但是那里的答案不是我需要的。 我想为不同的请求设置不同的超时时间,这就是我不想继承 RKObjectManager 的原因。我正在使用getObjectsAtPath:parameters:success:failurepostObject:path:parameters:success:

有没有办法分别设置每个请求的超时时间?

【问题讨论】:

    标签: ios timeout restkit


    【解决方案1】:

    在使用getObjectsAtPath:parameters:success:failurepostObject:path:parameters:success: 时不会。

    您需要改为调用requestWithObject:method:path:parameters:,然后编辑请求以设置超时,然后调用objectRequestOperationWithRequest:success:failure: 以使操作运行,然后调用enqueueObjectRequestOperation: 以使其执行。

    【讨论】:

    • 感谢您的回答。你知道我是否可以为该请求设置预期的状态码吗?我正在发送 POST,我从服务器收到 201,但 objectRequestOperationWithRequest:success:failure: 认为这是失败
    • 您是如何配置响应映射的?那是你设置代码的地方。
    • 这是我的代码:RKObjectMapping *messageRequestMapping = [RKObjectMapping requestMapping ]; // Shortcut for [RKObjectMapping mappingForClass:[NSMutableDictionary class] ] [[messageRequestMapping addAttributeMappingsFromArray:@[@"to", @"msg"]]; // Now configure the request descriptor RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:messageRequestMapping objectClass:[CuePostMessage class] rootKeyPath:nil method:RKRequestMethodAny]; [objectManager addRequestDescriptor:requestDescriptor]; 我将代码放在哪里?
    • 我的意思是输入响应描述符(不是响应映射),但您仍然显示了请求...
    • 所以我正在使用 RKRequestDescriptor。
    猜你喜欢
    • 2018-01-18
    • 2017-06-20
    • 2022-12-11
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 2017-06-28
    相关资源
    最近更新 更多