2014-03-27 51 views
0
我有我的本地主機的問題loggingout這是通過使用Drupal的7 由 https://github.com/kylebrowning/drupal-ios-sdk 首先提到我已經配置好了一切實現

,我要感謝kylebrowning爲他花費大量的時間,創造這個真棒SDK。 我面臨的問題是我可以很好地登錄,但我註銷失敗。 我NSLog看到代碼的錯誤。 這是在輸出標籤上顯示的錯誤。 我沒有足夠的信譽來發布兩個以上的鏈路 這裏是我下面的HTTP,「192.168.1.24/drupal/rest/user/logout」AFNetworkingError在IOS SDK的Drupal

域= AFNetworkingErrorDomain代碼= -1011「預期的狀態裏面是什麼代碼在(200-299),得到401「UserInfo = 0x8c4d6c0 {NSLocalizedRecoverySuggestion = [」CSRF驗證失敗「],AFNetworkingOperationFailingURLRequestErrorKey = {URL:」>「http://},NSErrorFailingURLKey = http :, NSLocalizedDescription =預期狀態代碼在(200-299),得到401,AFNetworkingOperationFailingURLResponseErrorKey = {URL:http://} {狀態碼:401,頭部「Cache-Control」=「no-cache,must-revalidate,post-check = 0,pre -check = 0" ; Connection =「Keep-Alive」; 「Content-Length」= 26; 「Content-Type」=「application/json」; 日期=「2014年3月27日星期四09:10:32 GMT」; Etag =「\」1395911432 \「」; 到期=「Sun,19 Nov 1978 05:00:00 GMT」; 「Keep-Alive」=「timeout = 5,max = 98」; 「Last-Modified」=「Thu,27 Mar 2014 09:10:32 +0000」; Server =「Apache/2.2.25(Unix)mod_ssl/2.2.25 OpenSSL/0.9.8y DAV/2 PHP/5.5.3」; 「Set-Cookie」=「SESS0fd8593946486e6ecd06721db47d9fe9 = deleted; expires = Thu,01-Jan-1970 00:00:01 GMT; Max-Age = 0; path = /; httponly」; Vary = Accept; 「X-Powered-By」=「PHP/5.5.3」; }}}

這裏是我的代碼

#import "AfterLoginViewController.h" 
#import "DIOSUser.h" 
#import "DIOSSession.h" 
#import "DIOSSystem.h" 
@interface AfterLoginViewController() 

@end 

@implementation AfterLoginViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 
- (IBAction)LogOut { 
    [DIOSUser 
    userLogoutWithSuccessBlock:^(AFHTTPRequestOperation *op, id response) 
    { 
     [self alertStatus:@"Logout Successful" :@"Sign Out Successful" :0]; 
     NSLog(@"Logout Successful"); 
     [self alertStatus:@"LogOut Successful" :@"LogOut is completed" :0]; 
     [self performSegueWithIdentifier:@"BackToLogin" sender:self]; 
     /* Handle successful operation here */ 
    } 

    failure:^(AFHTTPRequestOperation *op, NSError *err) 
    { 
     [self alertStatus:@"LogOut Failed" :@"LogOut failed Please Try Again !!!" :0 ]; 
     NSLog (@"Signout failed"); 
     NSLog (@"%@", err); 
    } 
    ]; 

} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 
- (void) alertStatus:(NSString *)msg :(NSString *)title :(int) tag 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title 
                 message:msg 
                 delegate:self 
               cancelButtonTitle:@"Ok" 
               otherButtonTitles:nil, nil]; 
    alertView.tag = tag; 
    [alertView show]; 

} 


- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

我將非常感激,如果有人可以幫助我這個問題。

回答

0

找到DIOSSystem 類這種方法

+ (void)systemConnectwithSuccess: (void (^)(AFHTTPRequestOperation *operation, id responseObject)) success 
    failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error)) failure { 
DIOSSession *session = [DIOSSession sharedSession]; 
[session getCSRFTokenWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {...} 

,並檢查是否在getCSRFTokenWithSuccess令牌被正確地設置好的,如:

- (void)getCSRFTokenWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success 
        failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/services/session/token", [[DIOSSession sharedSession] baseURL]]]]; 
[request setValue:[NSString stringWithFormat:@"text/plain"] forHTTPHeaderField:@"Accept"]; 
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    NSString *aCsrfToken = [NSString stringWithUTF8String:[responseObject bytes]]; 
    [[DIOSSession sharedSession] setCsrfToken:aCsrfToken]; 
    if (success != nil) { 
     success(operation, responseObject); 
    } 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    [DIOSSession logRequestFailuretoConsole:operation withError:error]; 
    if (failure != nil) { 
     failure(operation, error); 
    } 
}]; 
operation.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"application/json", nil]; 
operation.responseSerializer = [AFHTTPResponseSerializer serializer]; 
[self.operationQueue addOperation:operation]; 

}

最後用這個,對我的作品:

[DIOSUser 
userMakeSureUserIsLoggedOutWithSucess:^(AFHTTPRequestOperation *op, id response) { 
    NSLog(@"LogOut success!"); 

} 
failure:^(AFHTTPRequestOperation *op, NSError *err) { 
    NSLog(@"LogOut error: %@",err); 

} 
];