以下代码用于使用以下代码post
向服务器发出请求AFHTTPClient
:
NSURL *url = [NSURL URLWithString:urlString];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
//objects and keys
nil];
[httpClient postPath:postPath parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
id results = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONWritingPrettyPrinted error:nil];
//completion block
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}];
[httpClient release];
但我注意到,即使用户从当前弹出,请求仍在运行viewController
(当记录超时错误时注意到,当在另一个时viewController
)。
viewController
当不再在视图层次结构中时,如何停止请求。