2011-10-21 202 views
-1

我正在創建一個登錄應用程序,用戶可以在其中登錄。如何從服務器獲取數據?

如果用戶已經註冊,那麼他應該可以使用與服務器上保存的相同數據登錄,並且應該能夠將警報視圖作爲成功,如果不是錯誤警報。

不幸的是,我無法做到這一點。

請幫我一把。

這是我的代碼:

-(IBAction)btn_login: (id) sender 
{ 

NSString *firstname = Firstname.text; 

NSString *lastname = Lastname.text; 

NSString *post = [NSString stringWithFormat:@"fname=%@&lname=%@",firstname,lastname]; 

NSString *hostStr [email protected]"http://www.yoursite.com/iphone.php"; 
hostStr = [hostStr stringByAppendingString:post]; 
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStr]]; 

NSString *serverOutput = [[NSString alloc]initWithData:dataURL encoding:NSASCIIStringEncoding]; 

if ([serverOutput isEqualToString:@"Yes"]) 
{ 
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Congrats" message:@"You are authorised" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil]; 
    [alert show]; 
    [alert release]; 

} 
else { 
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Invalid Username and password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil]; 
    [alert show]; 
    [alert release]; 
} 

Firstname.text=nil; 
Lastname.text=nil; 

} 

感謝

+0

試着把斷點和檢查serverOutput的內容是什麼... – iAmitWagh

+0

k我會chk .....謝謝 – Nilesh

+0

你是否從服務器端獲得任何輸出? –

回答