How to cancel network request with afnetworking
12,990
Solution 1
[[httpClient operationQueue] cancelAllOperations];
Solution 2
Don't Create new AFHTTPClient
instance.
try "[self cancelAllHTTPOperationsWithMethod:@"POST" path:@"product/like"];
Solution 3
Both the other two answers are right. Don't Create new AFHTTPRequestOperationManager instance
@interface OperateCustomerView () <WYPopoverControllerDelegate>{
AFHTTPRequestOperationManager *manager;// = [AFHTTPRequestOperationManager manager];
}
- (void)viewDidLoad {
[super viewDidLoad];
manager = [AFHTTPRequestOperationManager manager];
![Jason Zhao](https://i.stack.imgur.com/5Yj6v.jpg?s=256&g=1)
Author by
Jason Zhao
Updated on June 13, 2022Comments
-
Jason Zhao about 2 years
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!