0
在郵差:AFNetworking錯誤域= com.alamofire.error.serialization.response代碼= -1011 「請求失敗:錯誤的請求(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:@"[email protected]" 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];
}];
由於覆蓋的是顯示錯誤。謝謝 –
我有同樣的問題,但解決'manager.requestSerializer = [AFJSONRequestSerializer序列化程序];' – Shahrukh