2

我尝试制作一个可以登录到使用 https 保护用户信息的 Web 应用程序的 iphone 应用程序。现在我被困在登录页面中。通过我的应用程序登录时,我不知道如何在用户的网站上查看真实帐户。即使我输入了错误的帐户,我也只收到了 200 条回复。

这是我的代码:

- (IBAction)clickOK:(id)sender {

NSURL *url = [NSURL URLWithString:@"https://www.freelancer.com/users/login.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

[request setUseKeychainPersistence:YES];
[request setDelegate:self]; 
request.shouldPresentCredentialsBeforeChallenge = YES; 

[request setRequestMethod:@"POST"];
[request setPostValue:usernameField.text forKey:@"username"];
[request setPostValue:passwordField.text forKey:@"passwd"];


request.timeOutSeconds = 30; 

[request setDidFailSelector:@selector(requestLoginFailed:)];
[request setDidFinishSelector:@selector(requestLoginFinished:)];
[request startAsynchronous];

}


- (void)requestLoginFailed:(ASIHTTPRequest *)request
{
//notify user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];

}

- (void)requestLoginFinished:(ASIHTTPRequest *)request
{
int statusCode = [request responseStatusCode];
NSString *statusMessage = [request responseStatusMessage];

NSLog(@"StatusCode: %d", statusCode);
NSLog(@"StatusMessage: %@", statusMessage);

}

谁能建议我如何检查本网站的真实帐户并保持用户登录?

谢谢你的帮助

4

1 回答 1

0

你已经异步启动了一些东西

[request startAsynchronous];

然后只是期望它会立即返回一些东西:

NSLog(@"%@",[request responseString]);
NSLog(@"%d",[request responseStatusCode]);

你需要这样写:

[request setDidFinishSelector:@selector(didFinishRequest:)];

然后将您的 NSLogs 和任何其他从响应中汲取的东西移到该方法中。

于 2012-06-20T16:51:14.743 回答