AFNetworking Error Domain = com.alamofire.error.serialization.response Code = -1011"请求失败:错误请求(400)"

时间:2016-05-31 14:06:23

标签: objective-c afnetworking-2

在POSTMAN中:

http://i.stack.imgur.com/GoFMq.png

我得到了回复但是在XCode中我收到了错误,这是我的代码:

NSString *tokenStr=[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults]objectForKey:@"token"]];

NSString *newString = [tokenStr stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSLog(@"Token iss %@",newString);

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

[manager.requestSerializer setValue:newString forHTTPHeaderField:@"Authorization-Token"];
[manager.requestSerializer setValue:@"5C063BDB-40EC-4EDE-8C0C-830D4437E056" forHTTPHeaderField:@"Authorization-Key"];
[manager.requestSerializer setValue:@"test@Simulationiq.com" forHTTPHeaderField:@"UserName"];
[manager.requestSerializer setValue:@"123456" forHTTPHeaderField:@"UserPassword"];

manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];



manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"text/plain", nil];



[manager GET:BaseURLStringLogin parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Bhai Error: %@", error);
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Data"
                                                                                          message:[error localizedDescription]
                                                                                         delegate:nil
                                                                                cancelButtonTitle:@"Ok"
                                                                                otherButtonTitles:nil];
                                      [alertView show];

}];

1 个答案:

答案 0 :(得分:4)

从服务器返回HTTP 400错误,这意味着服务器端应用程序对您的请求有些不满意。如果您有权访问服务器日志,请调查它们,看看它们是否提供了有关丢失/格式错误的详细信息。

但是,从我看来,我看到您在java.lang.RuntimeException: Method cancel in android.os.CountDownTimer not mocked. See ...上设置了一堆值,但随后使用默认manager.requestSerializer覆盖manager.requestSerializer,这意味着您的所有自定义配置值会被覆盖。在序列化器分配后尝试设置配置值

manager.requestSerializer = [AFHTTPRequestSerializer serializer];