需要这样设置 :
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
// AFPropertyListResponseSerializer AFHTTPResponseSerializer AFJSONResponseSerializer
/**
这两个 必须设置
*/
manager.responseSerializer = [AFPropertyListResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"text/plain",nil];
//设置请求头 压缩
[manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[manager.requestSerializer setTimeoutInterval:15];
另外一种方法
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
// AFPropertyListResponseSerializer AFHTTPResponseSerializer AFJSONResponseSerializer
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"text/plain",nil];
NSDictionary *paramter = @{
@"UserName":@"123456",
@"Password":@"123456a",
};
[manager POST:url parameters:paramter progress:^(NSProgress * _Nonnull uploadProgress) {
;
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
//需要转换一下
NSString *receiveStr = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@",receiveStr);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error ===: %@",error);
}];