1

As titled, and how to check HTTP status of response?

For example, if the server returns http status code 403, I need to send a recall mail request again to take new access token.

chubao
  • 5,871
  • 6
  • 39
  • 64
Abamazi
  • 39
  • 5

1 Answers1

0

Take a look at the below. In the failure block, retry/resend your query X number of times. Be sure to add logic to end retries at some point, so you don't end up with an infinite loop.

AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];

[operationManager POST:url
            parameters:object
               success:^(AFHTTPRequestOperation *operation, id responseObject) {
               }
               failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                   if (operation.response.statusCode == 403) {
                   // retry
                   }
               }
 ];

This answer may also be helpful.

Community
  • 1
  • 1
JaredH
  • 2,338
  • 1
  • 30
  • 40
  • @Abamazi Please note that this answer is based on afnetworking 2.x since 3.x has removed AFHTTPRequestOperationManager as detailed here: https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-3.0-Migration-Guide – chubao Jan 17 '16 at 12:13