gpt4 book ai didi

ios - AFHTTPRequestOperation 同步请求

转载 作者:行者123 更新时间:2023-11-29 03:30:37 28 4
gpt4 key购买 nike

我有这样一种情况,我需要向服务器发出多个请求,而后续请求将取决于先前的请求

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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com