我遇到了使用Drupal 7实现的Localhost登出问题 我按照https://github.com/kylebrowning/drupal-ios-sdk的提法配置了所有内容 首先,我要感谢kylebrowning花费了大量时间来创建这个非常棒的SDK。 我面临的问题是我可以正常登录,但我没有注销。 我NSLog看到代码的错误。 这是输出选项卡上显示的错误。 我没有足够的声誉来发布两个以上的链接 这是我的http下面的内容,“192.168.1.24/drupal/rest/user/logout”
Domain = AFNetworkingErrorDomain Code = -1011“(200-299)中的预期状态代码,得到401”UserInfo = 0x8c4d6c0 {NSLocalizedRecoverySuggestion = [“CSRF验证失败”],AFNetworkingOperationFailingURLRequestErrorKey = {URL:“>” http://},NSErrorFailingURLKey = http:,NSLocalizedDescription =(200-299)中的预期状态代码,得到401,AFNetworkingOperationFailingURLResponseErrorKey = {URL:http://} {status code:401,headers { “Cache-Control”=“no-cache,must-revalidate,post-check = 0,pre-check = 0”; 连接=“保持活力”; “内容长度”= 26; “Content-Type”=“application / json”; 日期=“星期四,2014年3月27日09:10:32 GMT”; Etag =“\”1395911432 \“”; Expires =“Sun,1978年11月19日05:00:00 GMT”; “Keep-Alive”=“timeout = 5,max = 98”; “Last-Modified”=“星期四,2014年3月27日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 =删除; expires = Thu,01-Jan-1970 00:00:01 GMT; Max-Age = 0; path = /; httponly”; 变化=接受; “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 :(得分: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);
}
];