0

I have multiple http requests, but they must combine one parameter named "accessToken" which rely on another individual request's response to send the server.

For example, I have request1,request2,request3,request4,request5 ,maybe more and more .These requests in everywhere ,I don't want to control it like this:

[self.AFRequestManager GET:@"individual reqeust" parameters:allParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSDictionary *parameters = @{@"accessToken":responseObject[@"data"]};
    [self.AFRequestManager GET:@"reqeust1" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    }];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];

So when I send all these requests one by one ,how to control the relationship between them?

Hilen
  • 761
  • 7
  • 8
  • you should use `NSOperationQueue` with dependency to handle multiple dependent requests. [Refere tutorial here](http://nshipster.com/nsoperation/) – Dipen Panchasara Aug 11 '15 at 06:00
  • tks, I've been read the Refere tutorial. But I design it in another way, if I did't send the parameter accessToken, after the request‘s response, the server will give an accessToken error. And then I will send the accessToken, after that, the reqeust will call itself. And I can finish this operation in a closed loop. if so, how to do it? – Hilen Aug 11 '15 at 07:00
  • as you use dependency it will start dependent task after first is completed and in that second task you can put a check for accessToken. – Dipen Panchasara Aug 12 '15 at 13:14

0 Answers0