我正在開發基於視圖的應用程序。當我們登錄頁面時,我們點擊登錄按鈕它應該檢查輸入的值與Web服務器值,它應該顯示瓦利或invalid.I以這種方式已經wriiten代碼被執行成功我得到的結果是這樣如何使用Web服務器值驗證用戶名和密碼在我的電話應用程序
<!DOCTYPE html PUbLIC" -//W3C//DTD XHTML 1.0 Strict....
什麼,我需要改變在下面的代碼與服務器comapre values..can任何一個可以幫助我對此請.. 。
-(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:@"https://108.16.210.28/Account/LogOn"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] retain];
}
else
{
}
[nameInput resignFirstResponder];
[passInput resignFirstResponder];
nameInput.text = nil;
passInput.text = nil;
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[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];
}
- (void)dealloc {
[super dealloc];
}
@end
我們不是在這裏調試您的代碼。什麼,特別是,不工作?你有什麼嘗試? –
代碼工作正常,但基於代碼我應該能夠連接網絡服務器,如果服務器的值與輸入的值匹配,它應該顯示消息有效無效,但我得到的應用程序的第一行HTML代碼 – Haritha