我正在使用网络服务开发iOS应用。 为了给我的网络服务打电话,我决定使用AFNetWorking 2.0。 我有一个大问题: 在命令行上我使用curl:
curl -X POST -d '[{"username":"user123","password":"querty"}]' -H "Content-Type: application/json" http://mysite
这很有效。
现在,当我想在iOS App上使用时:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json; text/html" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json; text/html; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSDictionary *parameters = @{@"username": @"user123", @"password":@"querty"};
[manager POST:@"http://mysite" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
我收到此错误: 请求失败:不可接受的内容类型:text / html