开发者

My app logs in twice with a URLRequest

When i press login in my app, it logs in twice in API instead of just once.., there is something wrong with this but i cant find what, because it just execute this code once.

   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];


There are two requests in the code:

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

and five lines down

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

Hint: In cases like this use wireshark or my favorite Charles which will decode SSL connections.


I guess it is possible. I mean, I am running APEX at this very moment and I have the same app. running in 3 different windows under the same user without having to log on. The only time I have to log on is when I change user. So yes, it is possible, but not sure why it is not working at your end. Could it be that you run both development and runtime at the same time using different users? Because if one of the APEX users differs from the other then you are prompted to log on again with the other user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜