I want my application to authenticate against the device, passing the username and password over https.
I looked through a few examples and basically create the following:
-(void)authentication
{
NSString *urlString =[NSString
stringWithFormat:
@"http://%@",appliance_IP.text];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
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 I use examples that, as I understand it, need a deeper understanding, NSURLConnection in the above example does not contain a username and password, how to add it? therefore, the request will also contain a username and password, or perhaps it is better to pass this information. Currently, the request contains only the url string.
Thanks er
user552120
source
share