对我来说,我已经完成了 asi http 请求。但是当我在登录页面上调用此方法时。如何为错误登录设置身份验证警报 View ,下面是 ASI HTTP 请求的方法
-(void) authenticateNSString*) uname passwordNSString*) pwd{
NSString *format = @"%s %d";
NSLog(format, __FUNCTION__);
myAppDelegate *appDelegate = (myAppDelegate *) [[UIApplication sharedApplication]delegate];
appDelegate.HUD.progress = 0.1f;
appDelegate.HUD.labelText = @"Authenticating...";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat"http://%@/login",appDelegate.appData.server]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
request.shouldPresentCredentialsBeforeChallenge = YES;
[request addBasicAuthenticationHeaderWithUsername:uname andPassword:pwd];
[request setDidFailSelectorselector(authenticationFailed];
request.userInfo = [NSDictionary dictionaryWithObject"authenticate" forKey"type"];
[request setDelegate:self];
[request startAsynchronous];}
Best Answer-推荐答案 strong>
- (IBAction)login_btnid)sender {
// secondview *second=[[secondview alloc]initWithNibName"secondview" bundle:nil];
// [self.navigationController pushViewController:second animated:YES];
// [second release];
/*
triangletechniqa.com/projects/funny/webservic/login.php?username=admin&password=123
*/
NSString *post =[NSString stringWithFormat"username=%@&password=%@",uesrname_text.text,password_text.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString"http://itriangletechniqa.com/projects/funny/webservic/login.php?"]];
[request setHTTPMethod"OST"];
[request setValue:postLength forHTTPHeaderField"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",str);
// NSMutableArray *tempArr = [str JSONValue];
// NSLog(@"%@",tempArr);
if([str isEqualToString:@"0"])
{
UIAlertView *unsucess=[[UIAlertView alloc]initWithTitle:@"Sorrrrry" message:@"Incurrect username and password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[unsucess show];
[unsucess release];
}
else
{
UIAlertView *success = [[[UIAlertView alloc]initWithTitle:@"successful" message:@"angry"
delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil] autorelease];
[success show];
secondview *view=[[secondview alloc]initWithNibName:@"secondview" bundle:nil];
[self.navigationController pushViewController:view animated:YES];
[view release];
}
}
关于iphone - 当 ASI Http Request 上的用户名或密码验证错误时,如何设置警报?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/13577990/
|