本文介绍了iPhone中服务器数据库中的验证用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,我正在这里验证服务器数据库中的用户名和密码通过给定服务器的URL,我认为我要出错了,我不认为我的代码是正确的请一些帮助我如何从服务器数据库验证iphone中的用户名和密码
hi friends i am doing here validation for username and password from server databaseby given url of server i think i am going wrong i don't think my code is rightplease some help me how to validation from server database for username and password in 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];
}
推荐答案
尝试使用以下 HTTPHeaderFields 进行设置.
Try setting with the following HTTPHeaderFields.
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"UTF-8" forHTTPHeaderField:@"charset"];
[request setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"];
我相信登录调用可能是"GET"方法,而不是"POST".
I believe that the login call may be a "GET" method instead of "POST".
再次确认您拨打电话的服务器URL.
Once again confirm with the server URL that you make the call.
谢谢.
这篇关于iPhone中服务器数据库中的验证用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!