我最近开始在我的项目中使用 AfNetworking。我创建了一个 AFClient,实现了所有的参数,一切都是为了GET方法。但是,我无法创建POST方法:有我的代码:
NSDictionary *params = [[NSDictionary alloc]initWithObjectsAndKeys:
@"TexttoInsert", @"question",
id,@"user_id",
nr1,@"number1",
nr2, @"number2",
nil];
[[MYClient sharedInstance] postPath:@"insert" parameters:params success:^(AFHTTPRequestOperation *operation, id JSON) {
NSLog(@"%@", JSON);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"RequestOperation:%@",operation);
NSLog(@"Error:%@",error);
}];
我收到此错误,无法解决。
Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x6cb6330 {NSLocalizedRecoverySuggestion={"success":false,"error":400,"message":"Bad Request"},
AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x6a893e0>, NSErrorFailingURLKey=http://myMainUrl/insert, NSLocalizedDescription=Expected status code in (200-299), got 400, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://myMainUrl/insert>}