您好我正在使用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.
}];
如何取消此请求???
答案 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]
?