我正在使用AFNetworking
pod' AFNetworking','〜> 2.2'
我需要发送一个带有json标头的POST,但它的结果为
"内容类型" =" text / html&#34 ;;
为什么??,请参阅我的代码即时设置这个?
- (void)postRequestWithParams:(NSDictionary*)paramasDicto andURL:(NSString*)url
success:(void (^)(id responseObject))success
failure:(void (^)(NSError *error))failure
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager
POST:url
parameters:paramasDicto
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
success(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(error);
DLog(@"error : %@", error);
}];
}
请注意,如果我这样做:po manager.requestSerializer.HTTPRequestHeaders
我得到了
{
"Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
"Content-Type" = "application/json";
"User-Agent" = "OrderingShopPhone/1.0 (iPhone Simulator; iOS 7.1; Scale/2.00)";
}
答案 0 :(得分:1)
the relevant AFNetworking code中的任何内容都无法设置text/html
。
可能的解释:
旁注:自2.2版以来,已经有很多重要的错误修复;你应该更新到2.3.1,虽然我不认为它会解决这个问题。