How to cancel network request with afnetworking

Jason Zhao picture Jason Zhao · Jun 17, 2012 · Viewed 13k times · Source

Is there a way to cancel all network request (the request started by another method) before I do a network request with AFNetworking I tried like below but not work:

- (void)sendRequest:(NSUInteger)page{


NSURL *aUrl = [NSURL URLWithString:@"http://www.abc.com/"];
AFHTTPClient *httpClientToCancel = [[AFHTTPClient alloc] initWithBaseURL:aUrl];
[httpClientToCancel cancelAllHTTPOperationsWithMethod:@"POST" path:@"product/like"];
[httpClientToCancel release];

... start a new request here .....

But not work. I just want to cancel all request (at least the request I wrote above) before I start a new request.

Thank you!

Answer

mattt picture mattt · Jun 18, 2012

[[httpClient operationQueue] cancelAllOperations];