Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 我的应用程序使用URL请求登录两次_Iphone_Objective C_Ios_Ipad - Fatal编程技术网

Iphone 我的应用程序使用URL请求登录两次

Iphone 我的应用程序使用URL请求登录两次,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,当我在我的应用程序中按login时,它在API中登录了两次而不是一次..,这有点问题,但我找不到什么,因为它只执行了一次代码 NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; NSHTTPURLResponse * response; NSError * error; NSMutableURLReque

当我在我的应用程序中按login时,它在API中登录了两次而不是一次..,这有点问题,但我找不到什么,因为它只执行了一次代码

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

代码中有两个请求:

[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
还有五行

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

提示:在这种情况下,请使用wireshark或我最喜欢的Charles来解码SSL连接。

我想这是可能的。我的意思是,我现在正在运行APEX,我有同样的应用程序。在同一用户下的3个不同窗口中运行,无需登录。我唯一需要登录的时间是更改用户时。
所以,是的,这是可能的,但不确定为什么它在你这边不起作用。是否可以使用不同的用户同时运行开发和运行时?因为如果APEX用户中的一个与另一个不同,则系统会提示您与另一个用户重新登录。

可能您的网站会处理该请求,然后意外发送重定向,该重定向也是由
NSURLConnection
执行的,这会导致两个HTTP Post请求,并且您的Web服务器也会对该请求执行您的操作第二个请求。这可以使用wireshark或Web服务器日志进行检查。(这只是一个想法)不,问题不在于我从API调用的函数,因为如果有人从其他方式(网站、windows程序等)调用此函数,它会登录一次