Cancel Post request in Afnetworking 2.0

梦想的初衷 提交于 2019-12-01 03:26:17

问题


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


回答1:


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



回答2:


Tried [manager.operationQueue cancelAllOperations] ?



来源:https://stackoverflow.com/questions/23512553/cancel-post-request-in-afnetworking-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!