Проверка подлинности IOS https
Я хочу, чтобы мое приложение проходило аутентификацию на устройстве, т.е. передавая имя пользователя и пароль через 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];
}
Поскольку я использую примеры, которые я взял, мне нужно больше понимания, NSURLConnection в приведенном выше примере не содержит имя пользователя и пароль, как мне его добавить? поэтому запрос также будет содержать имя пользователя и пароль или, возможно, лучше передать эту информацию. В настоящее время запрос содержит только строку URL.
Спасибо ER