2011-11-15 4 views
-1

私はビューベースのアプリケーションを開発しています。ログインボタンをクリックすると、Webサーバーの値で入力された値をチェックし、valiまたはinvalid.Iそれは成功した私はいずれかがこれをしてくださいについての私を助けてvalues..canサーバとcomapreするためのコードの下で変更する必要が私の電話アプリケーションでWebサーバーの値でユーザー名とパスワードを検証する方法

<!DOCTYPE html PUbLIC" -//W3C//DTD XHTML 1.0 Strict.... 

何この方法で結果を取得しています実行され、このようにコードをwriitenています。..

-(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 
+0

私たちはあなたのコードをデバッグするためではありません。具体的に何が働いていないのですか?何を試しましたか? –

+0

コードは正常に動作していますが、コードに基づいてWebサーバーに接続できる必要があります。サーバー値が入力値と一致する場合は無効なメッセージが表示されるはずですが、HTMLコード – Haritha

答えて

0

statusCodeを押してログイン状態を確認します。 didfoundcharacters.Ifで

あなたがdata.Ifを解析する必要があり、それがXMLデータの形式である、あなたが(有効のような)要素を解析する必要が
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 

    if([response isKindOfClass:[NSHTTPURLResponse class]]) 
    { 
     NSHTTPURLResponse *theResponse = (NSHTTPURLResponse*)response; 
     NSInteger theStatusCode = [theResponse statusCode]; 
     } 
} 
+0

のアプリケーションの最初の行を取得しています。ステータスコードも同じ以前の出力を得ています – Haritha

+0

ステータスコードにはどのような価値がありますか? – nanjunda

+0

[[NSString alloc] initWithFormat:@ "uname =%@&pwd =%@"、username、pass]; – Haritha

0

それが有効であることは、その後BOOL確認のような変数を作ります= NO; didfoundcharacters.ifでこれを修正してからさらにアクセスしてください

+0

私はどのように使うことができますか? – Haritha

関連する問題