1.找到 AFN 内AFURLRequestSerialization.m 文件第104行方法
- (NSString *)URLEncodedStringValue {
if (!self.value || [self.value isEqual:[NSNull null]]) {
return AFPercentEscapedStringFromString([self.field description]);
} else {
return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedStringFromString([self.field description]), AFPercentEscapedStringFromString([self.value description])];
}
}
修改成下面的
- (NSString *)URLEncodedStringValue {
if (!self.value || [self.value isEqual:[NSNull null]]) {
return AFPercentEscapedStringFromString([self.field description]);
}else if(!self.field || [self.field isEqual:[NSNull null]]){
return [NSString stringWithFormat:@"%@",self.value];
}else {
return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedStringFromString([self.field description]), AFPercentEscapedStringFromString([self.value description])];
}
}
2、参数字典转成Json 字符串
NSString* jsonStr = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:bodyDic options:0 error:nil] encoding:NSUTF8StringEncoding];
AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain", @"text/javascript", @"text/json", @"text/html", @"image/png",nil];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
AFJSONResponseSerializer *reponse = [AFJSONResponseSerializer serializer];
reponse.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain", @"text/javascript", @"text/json", @"text/html", @"image/png", nil];
reponse.removesKeysWithNullValues = YES;
manager.responseSerializer = reponse;
[manager POST:@"url" parameters:jsonStr success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
XXLog(@"guygi %@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
XXLog(@"errii == %@",error);
}]
网友评论