Using afnetworking, the server reference here
iOS, using your own serialization class
New ];
[Manager.requestserializer SetValue: @" gzip " Forhttpheaderfield:@"accept-encoding"];
[Manager.requestserializer SetValue: @" gzip " Forhttpheaderfield:@"content-encoding"];
H file
#import <Foundation/Foundation.h>"AFURLRequestSerialization.h"@ Interface Myhttprequestserializer:afhttprequestserializer@end
Key code, reference Afjsonrequestserializer
@implementation Myhttprequestserializer-(Nullable Nsurlrequest *) Requestbyserializingrequest: (Nsurlrequest *Request Withparameters: (nullable ID) parameters Error: (Nserror* _nullable __autoreleasing *) Error ns_swift_nothrow{Nsparameterassert (request); if([Self. Httpmethodsencodingparametersinuri containsobject:[[request HttpMethod] uppercasestring]) {return[Super Requestbyserializingrequest:request withparameters:parameters Error:error]; } nsmutableurlrequest*mutablerequest =[Request Mutablecopy]; [Self. Httprequestheaders Enumeratekeysandobjectsusingblock:^ (ID field, id value, BOOL *__unused stop) { if(![Request Valueforhttpheaderfield:field]) {[Mutablerequest setvalue:value Forhttpheaderfield:field]; } }]; if(parameters) {if(! [Mutablerequest Valueforhttpheaderfield:@"Content-type"]) {[Mutablerequest setValue:@"Application/json"Forhttpheaderfield:@"Content-type"]; } nsdata * data = [nsjsonserialization datawithjsonobject:parameters options: (nsjsonwritingoptions) 0 Error:nil]; nsdata* Zippeddata = [lfcgziputillity gzipdata:data]; [Mutablerequest Sethttpbody:zippeddata]; } returnMutablerequest;} @end
iOS under form post using gzip mode