AFNetworking 错误域=com.alamofire.error.serialization.response 代码=-1011 "Request failed: bad request (400)"
AFNetworking Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)"
在邮递员中:
我收到回复,但在 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];
}];
服务器返回 HTTP 400 错误,这意味着服务器端应用对您的请求不满意。如果您有权访问服务器日志,请调查它们并查看它们是否提供有关 missing/malformed.
的更多详细信息
不过,从外观上看,我看到您在 manager.requestSerializer
上设置了一堆值,但随后用默认值 manager.requestSerializer = [AFHTTPRequestSerializer serializer];
覆盖了 manager.requestSerializer
,这意味着您所有的自定义值配置值将被覆盖。尝试在 序列化程序分配 之后设置您的配置值:
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[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"];
在邮递员中:
我收到回复,但在 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];
}];
服务器返回 HTTP 400 错误,这意味着服务器端应用对您的请求不满意。如果您有权访问服务器日志,请调查它们并查看它们是否提供有关 missing/malformed.
的更多详细信息不过,从外观上看,我看到您在 manager.requestSerializer
上设置了一堆值,但随后用默认值 manager.requestSerializer = [AFHTTPRequestSerializer serializer];
覆盖了 manager.requestSerializer
,这意味着您所有的自定义值配置值将被覆盖。尝试在 序列化程序分配 之后设置您的配置值:
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[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"];