내 앱에서 login 키를 누를 때 API가 한 번만 입력되는 대신 두 번 로그인됩니다.이 코드에 오류가 있습니다.하지만이 코드를 실행하기 때문에 찾을 수 없습니다. 일단.내 앱이 URLRequest로 두 번 로그인합니다.
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
아래
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
힌트 다섯 줄 : 경우에 SSL 연결을 디코딩 할이 사용 와이어 샤크 또는 내가 좋아하는 찰스와 같은
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];
웹 사이트에서 요청을 처리 한 다음 실수로 두 개의 HTTP-Post 요청을 초래하는 NSURLConnection에 의해 수행되는 리디렉션을 보내고 웹 서버는 두 번째 요청에 대해 사용자 작업을 수행합니다. 이것은 wireshark 또는 webserver-logs를 사용하여 확인할 수 있습니다. (단지 아이디어 일뿐입니다.) – thomas
아니요, 누군가 다른 방식 (웹 사이트, 윈도우 프로그램 등)에서이 함수를 호출하면 API에서 호출하는 기능에 문제가 없습니다. 한 번 로그인하면됩니다. – Oblieapps