2011-09-10 1 views
1

私のアプリでloginを押すと、一度ではなくAPIで2回ログインします。何か問題がありますが、このコードを実行するだけで何が見つかりません一度。私のアプリはURLRequestを使って2回ログインする

NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];  
    NSHTTPURLResponse * response; 
       NSError    * error; 
       NSMutableURLRequest * request; 
       NSString   * params; 
       NSString *urlAddress = [NSString stringWithFormat:@"%@/?action=request&api=json&module=ManagementModule&function=startSession&instance=0",[ConnectServer returnserverip]]; 
       NSLog(@"UPX %@",[ConnectServer returnserverip]); 
       NSLog(@"IP %@",[ConnectServer returnclientip]); 
       if([defaults boolForKey:@"enablePincode"]){ 
        NSString *account = [defaults stringForKey:@"myAccount"]; 
        NSString *username =[defaults stringForKey:@"myUsername"]; 
        NSString *password = [defaults stringForKey:@"myPassword"]; 
        NSString *clientip = [ConnectServer returnclientip]; 
        NSString *clientname = [ConnectServer returnclientname]; 
        params = [[[NSString alloc] initWithFormat:@"params=&auth[password]=%@&auth[mode]=%@&auth[account]=%@&auth[user]=%@&auth[rights]=%@&auth[user_ip]=%@&auth[client_name]=%@",password,@"password",account,username,@"user",clientip,clientname] autorelease]; 
       } 
       else { 
        NSString *clientip = [ConnectServer returnclientip]; 
        NSString *clientname = [ConnectServer returnclientname]; 
        params = [[[NSString alloc] initWithFormat:@"params=&auth[password]=%@&auth[mode]=%@&auth[account]=%@&auth[user]=%@&auth[rights]=%@&auth[user_ip]=%@&auth[client_name]=%@",[myPassword text],@"password",[myAccount text],[myUsername text],@"user",clientip,clientname] autorelease]; 
       } 
       request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlAddress] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60] autorelease]; 
       NSData *myRequestData = [params dataUsingEncoding:NSUTF8StringEncoding]; 
       [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[[NSURL URLWithString: urlAddress] host]]; 
       [request setHTTPMethod:@"POST"]; 
       [request setHTTPBody:myRequestData]; 
       [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Accept"]; 
       [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
       [request setValue:[NSString stringWithFormat:@"%d", [myRequestData length]] forHTTPHeaderField:@"Content-Length"]; 
       [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
    NSLog(@"RESPONSE HEADERS: \n%@", [response allHeaderFields]); 
    request.URL = [NSURL URLWithString:urlAddress]; 
    error  = nil; 
    response = nil; 
    NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
    NSLog(@"The server saw:\n%@", [[[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding] autorelease]); 
    NSLog(@"Parameters: %@", params); 
    NSLog(@"Actual sended parameters to the server: %@", myRequestData); 
    NSString *Sresponse; 
    Sresponse = [[[NSString alloc] initWithData:data encoding: NSASCIIStringEncoding] autorelease]; 
+1

あなたのウェブサイトがリクエストを処理した後、偶発的にリダイレクトを送信します。リダイレクトは、NSURLConnectionによって実行され、2つのHTTP-Postリクエストが発生し、Webサーバーも2回目のリクエストに対してアクションを実行します。これは、wiresharkまたはwebserver-logsを使用して確認できます。 – thomas

+0

いいえ、他の方法(ウェブサイト、Windowsプログラムなど)からこの関数を呼び出すと、APIから呼び出す関数に問題がありません。一度ログインすると – Oblieapps

答えて

1

コード内の2つの要求があります

[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

と5行がダウン

NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

ヒント:SSL接続をデコードし、この使用のwiresharkまたは私のお気に入りのチャールズのようなケースでは。

1

と思います。つまり、私はこの時点でAPEXを実行しています。私は同じアプリを持っています。ログオンすることなく同じユーザーの下に3つの異なるウィンドウで実行できます。私がログオンする必要があるのは、ユーザーを変更するときだけです。 はい、それは可能ですが、なぜそれがあなたの最後に働いていないのか分かりません。異なるユーザーを使用して、開発とランタイムの両方を同時に実行することができますか? APEXユーザーの1人が他のユーザーと異なる場合は、もう1人のユーザーと再度ログオンするよう求められます。

関連する問題