iosafnetworking-3

GZip my AFNetworking posts to my server


My application posts large amounts of data, Orders with Order Items - sometimes 1000's, and I want to send it GZipped because my users also have crappy connections most of the time.

How can I accomplish this with AFnetworking?

I am currently using AFHTTPSessionManager to perform my posts.


Solution

  • You can use AFgzipRequestSerializer.

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFgzipRequestSerializer serializerWithSerializer:[AFJSONRequestSerializer serializer]];
    
    [manager POST:@"http://example.com/"
       parameters:@{@"foo": @"bar"}
          success:^(NSURLSessionDataTask *task, id responseObject) {
            NSLog(@"%@", responseObject);
    }
          failure:^(NSURLSessionDataTask *task, NSError *error) {
            NSLog(@"[Error] %@", error);
    }];
    

    See details here.