是否可以重试ASIHTTPRequest? [英] Can an ASIHTTPRequest be retried?
问题描述
有没有办法重试ASIHTTPRequest?我在REST服务中使用自定义身份验证而不是基本HTTP身份验证,如果会话已过期,我想重试请求。在请求上第二次调用startAsynchronous会导致异常。我想做这样的事情:
Is there a way to retry an ASIHTTPRequest? I'm using custom authentication in a REST service instead of basic HTTP authentication and I would like to retry a request if the session has expired. Calling startAsynchronous a second time on a request causes an exception. I would like to do something like this:
[request setCompletionBlock:^{
if ([request responseStatusCode] == 500)
{
// try to login again in case token expired
[server loginAndRetryRequest:request];
} else {
// parse response
}
}];
loginAndRetryRequest:将执行另一个ASIHTTPRequest登录,一旦完成,它将再次从原始请求开始它是CompletionBlock(假设这可能以某种方式)?
loginAndRetryRequest: will do another ASIHTTPRequest to login and when it is complete it will start the original request again from it's CompletionBlock (assuming this is possible somehow)?
推荐答案
应该可以复制请求然后执行 -startAsynchronous
再次复制。
It should be possible to make a copy of the request and then execute -startAsynchronous
again on the copy.
在版本1.5中添加了对NSCopying协议的支持,其中还包括自动重试超时的情况(选择器 -setNumberOfTimesToRetryOnTimeout:
。
Support for NSCopying protocol was added in release 1.5, which also includes automatic retry in case of timeout (selector -setNumberOfTimesToRetryOnTimeout:
.
另一个选项可能是检查他们的源代码,看看自动如何在超时的情况下进行重试,但复制和重新发出请求应该有效(这是首先添加对NSCopying的支持的原因)。
Another option could be checking their source code to see how the automatic retry is done in case of timeout, but copying and re-issuing the request should work (that was the reason to add support for NSCopying in the first place).
这篇关于是否可以重试ASIHTTPRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!