• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

iphone - 当 ASI Http Request 上的用户名或密码验证错误时,如何设置警报?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 23:51:32 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

对我来说,我已经完成了 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-推荐答案


- (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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap