我在使用AFNetworking进行x-www-form-urlencoded POST时遇到了麻烦。我的代码如下:
NSString *uniqueIdentifier = @"Bob's iPhone";
NSString *code = self.textField.text;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:@"1", @"rw_app_id",code,@"code",uniqueIdentifier,@"device_id", nil];
[manager POST:@"http://www.somesite.co/promos/" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@",error);
}];
我收到错误: 错误域= com.alamofire.error.serialization.response代码= -1011“请求失败:禁止(403)”UserInfo = 0x7f8f8bf49550 {NSUnderlyingError = 0x7f8f8bf59910“请求失败:不可接受的内容类型:text / html“
我用Google搜索并尝试解决此问题,并使用以下命令更改了请求序列化程序:
manager.requestSerializer=[AFHTTPRequestSerializer serializer];
那里没有运气。我使用NSURLSession让我的服务器正常运行这些类型的请求。但我想让它适用于AFNetworking。有人可以给我一些指示我可能做错的事吗?
答案 0 :(得分:1)
这应该有帮助
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
或使用此responseSerializer
代替requestSerializer
manager.responseSerializer = [AFHTTPResponseSerializer serializer];