5

Hi I am making post request using AFnetworking 2.0. My request looks like this.

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
            manager.responseSerializer = [AFXMLParserResponseSerializer serializer];
            [manager.requestSerializer setValue:@"some value" forHTTPHeaderField:@"x"];

            [manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {

                //doing something

            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                // error handling.
            }];

How can i cancel this request???

Larme
  • 24,190
  • 6
  • 51
  • 81
Saif
  • 812
  • 1
  • 9
  • 18
  • possible duplicate of [AFNetworking 2: How to cancel a AFHTTPRequestOperationManager request?](http://stackoverflow.com/questions/20143877/afnetworking-2-how-to-cancel-a-afhttprequestoperationmanager-request) – Larme May 07 '14 at 08:33

2 Answers2

9

POST method return the AFHTTPRequestOperation operation. You can cancel it by calling cancel.

AFHTTPRequestOperation *post =[manager POST:nil parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
  //doing something
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
   // error handling.
}];

//Cancel operation
[post cancel];
Kostiantyn Koval
  • 8,407
  • 1
  • 45
  • 58
3

Tried [manager.operationQueue cancelAllOperations] ?

Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120
  • Hi setgiusGee. i have tried this it's not working. i have created instance of AFHTTPRequestOperationManager which is not a operation type. so i cant add this to nsoperationqueue.. – Saif May 07 '14 at 08:31
  • its not working "[manager.operationQueue cancelAllOperations]" – akshay Feb 19 '19 at 04:35