使用AFNetworking 2.0的POST JSON请求无效

时间:2014-06-05 13:27:23

标签: json afnetworking afnetworking-2

实际上,我已经将AFHTTPRequestOperationManager分类为进行服务调用。请求服务调用是带有JSON数据的POST,请参考以下代码以供参考

//在字典中构建JSON数据

NSMutableDictionary *createProfile = [[NSMutableDictionary alloc] init];
[createProfile setObject:@"XXXX" forKey:@"FirstName"];
[createProfile setObject:@"Kumar" forKey:@"MiddleName"];
[createProfile setObject:@"V" forKey:@"LastName"];
[createProfile setObject:@"xxxxxxxx@sify.com" forKey:@"email"];
[createProfile setObject:@"asdasdasd" forKey:@"Password"];
[createProfile setObject:@"Facebook" forKey:@"RegistrationSource"];
[createProfile setObject:@"" forKey:@"Device"];   
[createProfile setObject:@"" forKey:@"FavoriteStores"];

//服务电话配置

self.securityPolicy.allowInvalidCertificates = YES;

AFJSONRequestSerializer *reqSerializer = [AFJSONRequestSerializer serializer];
[reqSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[reqSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
self.requestSerializer = reqSerializer;

AFJSONResponseSerializer *resSerializer = [AFJSONResponseSerializer serializer];
[resSerializer setReadingOptions:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers];
resSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json", nil];
self.responseSerializer = resSerializer;

//最后,进行服务电话

[self POST:@"API/Signup" parameters:createProfile success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Success");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error %@", error);
}];

之后,拨打服务电话。我的数据正确填充在数据库中。但是,服务调用调用失败块,我收到如下错误消息,

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.
(Cocoa error    3840.)" (Invalid value around character 0.) UserInfo=
0x8e7a290{NSDebugDescription=Invalid value around character 0.,NSUnderlying
Error=0x8e7a150 "Request failed: unacceptable (406)"}

如果有人遇到这个问题,你能帮助我吗?

0 个答案:

没有答案