Я хочу, чтобы мое приложение было аутентифицировано против устройства, передавая имя пользователя и пароль по https.Проверка подлинности IOS https
Я посмотрел на нескольких примерах и в основном построить следующее:
-(void)authentication
{
//setting the string of the url taking from appliance IP.
NSString *urlString =[NSString
stringWithFormat:
@"http://%@",appliance_IP.text];
//define the url with the string
NSURL *url = [NSURL URLWithString:urlString];
//creating request
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//setting credential taking from the username and password field
NSURLCredential *credential = [NSURLCredential credentialWithUser:username.text password:password.text persistence:NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *protectionSpace=
[[NSURLProtectionSpace alloc]initWithHost:urlString port:443 protocol:@"https" realm:nil authenticationMethod:nil ];
[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential forProtectionSpace:protectionSpace];
[ NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];
}
AS Я использую примеры, которые я взял мне нужно больше понимания, NSURLConnection в примере выше, не содержит имя пользователя и пароль, как мне добавить его? поэтому запрос также будет содержать имя пользователя и пароль или, возможно, лучше передать эту информацию. В настоящее время запрос содержит только строку url.
Благодаря ER