iosafnetworkingafhttprequestoperation

AFNetworking POST AFHTTPRequestOperation Queue issue


I'm requesting data from the server but I have an issue that it is calling the cookie first than the data unlike it should be data first than cookie. So please how can I fix this issue?

I've seen this issue via Charles application.

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:string
   parameters:@{@"data": @"<p_LM act=\"info\"/>", @"cookie": [temp objectForKey:@"cookie"]}
      success:^(AFHTTPRequestOperation *operation, id responseObject) {

          NSDictionary *dic  = (NSDictionary *)responseObject;

          NSString *parity = [dic objectForKey:@"Response"];
}

Solution

  • Parameters is NSDictionary. When AF serialize the request it uses alphabetical sort descriptor for NSDictionary:

    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(compare:)];
    

    So, you have two choices:

    edited to specify the second way

    if you want to change the AFNetworking code pod to make it work for you then do:

    1. search for AFQueryStringPairsFromKeyAndValue method in AFNetworking pod

    2. change e.g.

      NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(compare:)];
      

      to

      NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:NO selector:@selector(compare:)];
      

      (just change alphabetical sorting from bottom to top)

    3. and then if you will update your AFNetworking pod next time after a year or earlier then just add this change again because your change will be overridden by the new pod update ...