ASIHTTPRequest Request Cancel

asihttprequest, iphone, objective-c, xcode

Solution

Your cancel specific ASIHTTPRequest then :

if(![yourASIHTTPRequest isCancelled]) 
{
    // Cancels an asynchronous request
    [yourASIHTTPRequest cancel];
    // Cancels an asynchronous request, clearing all delegates and blocks first
    [yourASIHTTPRequest clearDelegatesAndCancel];
}

Note : To cancel all ASIHTTPRequest then :

for (ASIHTTPRequest *request in ASIHTTPRequest.sharedQueue.operations)
{
  if(![request isCancelled]) 
  {
     [request cancel];
     [request setDelegate:nil];
  }
}

EDIT : Use AFNetworking as `ASIHTTPRequest` is deprecated as its has not been update since march 2011.

Problem

I have been using ASIHTTPRequest to fetch the data and i want to cancel the request how i do it?? i do the code just like this.. ``` -(void) serachData{ NSURL *url= [NSURL URLWithString:self.safestring]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setTimeOutSeconds:7200]; [request setDelegate:self]; [request startAsynchronous]; } - (NSMutableDictionary *)requestFinished:(ASIHTTPRequest *)request { NSLog(@"requestFinished"); NSString *responseString = [request responseString]; SBJsonParser *json = [[SBJsonParser alloc] init]; NSMutableArray *array = [[NSMutableArray alloc] initWithObjects[jsonobjectWithString:responseString], nil]; NSLog(@"array %@",array); } - (void)requestFailed:(ASIHTTPRequest *)request{ NSLog(@"requestFailed"); } ``` //if i press cancel button(when requestFinished /requestFailed method in process ) then the ASIHTTPRequest fail and finish method Stop /abort! how i do this?? ``` -(IBAction)CancleREquest:(id)sender{ NSLog(@"CancleREquest"); } ```

Original source