嗨朋友我在这里做服务器数据库验证用户名和密码 给定的服务器网址我想我错了我不认为我的代码是正确的 请一些帮助我如何从服务器数据库中的iphone验证用户名和密码验证用户名和密码从服务器数据库在iphone
-(IBAction)buttonClick:(id)sender
{
NSString* username = nameInput.text;
NSString* pass = passInput.text;
if([nameInput.text isEqualToString:@"" ]&& [passInput.text isEqualToString:@""])
{
//greeting.text = @"Input Your Value";
//[nameInput resignFirstResponder];
//[passInput resignFirstResponder];
//return;
}
NSString *post =
[[NSString alloc] initWithFormat:@"uname=%@ & pwd=%@",username,pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://server:85/VirtualTerminal/RecordAttendance.aspx"];//@"https://www.google.com/accounts/ServiceLogin?service=reader&passive=1209600&continue=http://www.google.co.in/reader/?hl%3Den%26tab%3Dwy&followup=http://www.google.co.in/reader/?hl%3Den%26tab%3Dwy&hl=en"]; //@"http://www.chakrainteractive.com/mob/iphone/login/chckusr.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] retain];
//test *t=[[test alloc]initWithNibName:@"test" bundle:nil];
//[self presentModalViewController:t animated:YES];
//[t release];
}
else
{
}
//}
[nameInput resignFirstResponder];
[passInput resignFirstResponder];
nameInput.text = nil;
passInput.text = nil;
k
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *loginStatus = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"loginStatus");
greeting.text = loginStatus;
[loginStatus release];
[connection release];
[webData release];
}
究竟发生了什么?你有没有尝试在你的委托方法中加入一些断点来查看它们是否被调用? – scalbatty 2011-04-07 11:51:35
嗨我把断点它工作正常,但如果把错误的用户名和密码它也工作我想如果用户名和密码匹配从服务器数据库然后下一页应该来我试试,但它不工作我对此stuk请帮助我 – user692277 2011-04-08 05:10:02