【发布时间】:2013-12-19 15:59:57
【问题描述】:
我正在尝试通过设置 HTTPAdditionalHeaders 为“Content-Type”设置默认标头。当我查看请求标头时,AFNetworking (v 2.0.3) 将其改回。我还尝试在 requestSerializer 上通过 setValue:forHTTPHeaderField: 设置标头,但没有成功。我错过了什么?
更新
NSURL *URL = [NSURL URLWithString:@"http://example.com/api"];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.HTTPAdditionalHeaders = @{@"Content-Type": @"multipart/form-data"};
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:URL sessionConfiguration:configuration];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
[params setValue:@"some value" forKey:@"someKey"];
[manager POST:@"search" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"success");
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"error");
}];
【问题讨论】:
-
您使用的是 AFNetworking 2.0.3 吗?
-
是的,AFNetworking 2.0.3
-
AFNeteworking 将 content-type 标头改回什么?
-
@Aaron Brager,AFNetworking 将其更改为“application/x-www-form-urlencoded; charset=utf-8”
标签: ios objective-c afnetworking afnetworking-2