在Afnetworking 2.0中取消发布请求

时间:2014-05-07 08:26:01

标签: ios afnetworking-2

您好我正在使用AFnetworking 2.0发帖请求。 我的请求看起来像这样。

 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.
            }];

如何取消此请求???

2 个答案:

答案 0 :(得分:9)

POST方法返回AFHTTPRequestOperation操作。您可以致电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];

答案 1 :(得分:3)

尝试[manager.operationQueue cancelAllOperations]