iOS under form post using gzip mode

Source: Internet
Author: User
Tags form post

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.