Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel Post request in Afnetworking 2.0

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???

like image 673
Saif Avatar asked May 07 '14 08:05

Saif


Video Answer


1 Answers

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];
like image 138
Kostiantyn Koval Avatar answered Oct 13 '22 22:10

Kostiantyn Koval