菜单
菜单

gzip数据压缩解析


1.需要服务器进行配置Content-Type 为gzip
2.AFN框架客户端使用下列代码即可
``OBJC
// 1.创建请求管理对象
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

[manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Content"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
manager.requestSerializer.timeoutInterval = timeoutInterval;

manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"application/json;charset=utf-8", @"text/json", @"text/javascript", @"text/plain",@"text/html", nil];

[manager POST:url parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {

// NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin1);

    NSString* strdata = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
    NSData *data = [strdata dataUsingEncoding:NSUTF8StringEncoding];


    NSMutableString *strM = [[NSMutableString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding];

    NSData* jsonData = [strM dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
 //   NSDictionary *dict = [NSDictionary initWithJsonString:strM.copy];

    if (success) {
        success(dict);
    }
} failure:^(NSURLSessionDataTask *task, NSError *error) {
    if (failure) {
        failure(error);
    }
}];

```

支持一下
天若有情天亦老,请我吃糖好不好