我有这样一种情况,我需要向服务器发出多个请求,而后续请求将取决于先前的请求
1) request 1
2) process data
3) request 2 based on data in step 2
4) process data
对于 AFNetworking 2,解决这个问题的最佳方法是什么
最佳答案
在第一个请求的完成处理程序中调用第二个请求。下面是一些示例代码:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON Response 1: %@", responseObject);
// Process data here, and use it to set parameters or change the url for request2 below
[manager GET:@"http://example.com/request2.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON Response 2: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error 2: %@", error);
}];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error 1: %@", error);
}];
关于ios - AFHTTPRequestOperation 同步请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19848415/