2016-05-31 199 views
0

在郵差:AFNetworking錯誤域= com.alamofire.error.serialization.response代碼= -1011 「請求失敗:錯誤的請求(400)」

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:@"[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]; 

}]; 

回答

3

即從服務器,這意味着服務器端應用程序返回的HTTP 400錯誤是不開心的東西對你的要求。如果您有權訪問服務器日誌,請查看它們並查看它們是否提供了有關缺少/格式錯誤的更多詳細信息。

距離看,不過,我看你設定一堆價值觀對你manager.requestSerializer,但隨後覆蓋manager.requestSerializer有默認manager.requestSerializer = [AFHTTPRequestSerializer serializer];,這意味着所有的定製的配置值將被覆蓋。嘗試串行分配設置你的配置價值後:

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:@"[email protected]" forHTTPHeaderField:@"UserName"]; 
[manager.requestSerializer setValue:@"123456" forHTTPHeaderField:@"UserPassword"]; 
+0

由於覆蓋的是顯示錯誤。謝謝 –

+0

我有同樣的問題,但解決'manager.requestSerializer = [AFJSONRequestSerializer序列化程序];' – Shahrukh

相關問題