我使用AFNetworking在for循环中调用web服务。 我想区分响应,即当前响应是针对当前索引还是其他索引。
AFHTTPRequestOperationManager对象是否有任何属性,以便我可以区分每个响应。
我需要根据响应对数组中的某个对象执行某些操作,因此我需要识别每个响应。
for (int i = 0; i < [array count]; i++) {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:requestAuthorization forHTTPHeaderField:@"Authorization"];
[manager.requestSerializer setValue:@"guest" forHTTPHeaderField:@"user_type"];
[manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forHTTPHeaderField:@"user_type"];
[manager.requestSerializer setValue:[[UIDevice currentDevice] systemVersion] forHTTPHeaderField:@"device_os"];
[manager.requestSerializer setValue:[[UIDevice currentDevice] systemName] forHTTPHeaderField:@"device_name"];
[manager.requestSerializer setValue:@"ugx9gdispQMa6SwmwbWjz5ApDuqCfRENm2ATbCy6" forHTTPHeaderField:@"X-Parse-Application-Id"];
[manager.requestSerializer setValue:@"AwwFiB7oEvYYZqAhPH0u9q8UozluVm110kVVrOHQ" forHTTPHeaderField:@"X-Parse-REST-API-Key"];
[manager.requestSerializer setValue:@"guest" forHTTPHeaderField:@"user_type"];
[manager GET:URL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error code %ld",(long)[operation.response statusCode]);
NSLog(@"Error: %@", error);
}];
}