English 中文(简体)
320 土耳其
原标题:three20 TTURLRequest resend

I have a REST service that uses an auth_token that expires every so often. when a request fails, I want to re-authenticate (which I m able to do) and then resend the same exact TTURLRequest in the following generic way:

- (void)request:(TTURLRequest*)request didFailLoadWithError:
(NSError*)error {
       NSLog(@"error %@ %@ %@", [error localizedDescription], [error
localizedFailureReason], [error localizedRecoverySuggestion]
                 );


       if (numRetries == 0) {
               [self authenticateUser:nil];

               request.urlPath = [request.urlPath
stringByReplacingOccurrencesOfRegex:@"access_token=([\w-]+)"
withString:[NSString stringWithFormat:@"access_token=%@",
accessToken]];

               NSLog(@"URL: %@", request.urlPath);
               [request   send];

               numRetries++;

       }

}

all of my TTURLRequests use the same delegate which uses this failure method. but for some reason, when I call [request send] the request gets to the "loading" phase, but does not ever seem to complete. However, if I do a manual refresh (by dragging down the table view) it re-generates the TTURLRequest from scratch and seems to work fine.

修改这一请求的正确方式是什么?

问题回答

我最近也谈到同样的问题。 我曾深入探讨过320次,以了解是否打算对失败的请求进行再研究,但我发现问题,是可靠的(简单)解决办法。

在[请求发出]后,TTURLRequeste公司在完成装货之前就得到分配。 如果你看三20Network的TTURLRequestModel.m,你就可以看到,在新申请获得保留之前,该模式即已被释放。 如果最后一项请求与新的请求(如你的情况)相同,则保留到0,并收到:

/////////////////////////////////////////////////////////////////////////////
- (void)requestDidStartLoad:(TTURLRequest*)request {
  [_loadingRequest release];
  _loadingRequest = [request retain];
  [self didStartLoad];
}

我通过将TTURLRequestModel.m分级解决了这一问题,并以以下方式推翻了这一方法:

/////////////////////////////////////////////////////////////////////////////////
- (void)requestDidStartLoad:(TTURLRequest*)request {
  [request retain];
  [_loadingRequest release];
  _loadingRequest = request;
  [self didStartLoad];
}

这在我的测试中发挥了作用,似乎它会给任何不利影响。

<说明>:如果你正在使用TTURLJSONResponse申请回复标语,你将需要安排新的试样,并安排申请。 在再次发出呼吁之前作出反应。 如果你看一下TTURLJSONResponse.m的话,请看一下处理方法(Nil=_rootObject)的说法。 如果在以前的请求中使用了答复小组的话,这将失败。





相关问题
Using PHP to find part of a URL

Take this domain: http://www.?.co.uk/elderly-care-advocacy/mental-capacity-act-advance-medical-directive.html How could i use PHP to find the everything between the first and second slash regardless ...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

Encoding of window.location.hash

Does window.location.hash contain the encoded or decoded representation of the url part? When I open the same url (http://localhost/something/#%C3%BC where %C3%BCtranslates to ü) in Firefox 3.5 and ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

采用网路服务方法

我撰写了一个网络服务,期望一个参数(所谓的“hlink”)成为一种ur。 在使用网络服务之前,URLEncode 所涉参数(“hlink”)。 然后我打电话......。

热门标签