I have been searching over the internet about the right configuration to send a POST to my server using HTTPS, some web pages say i need NSURLCredential
and others say:
Just use a @"https://www.myhttpsite.com/" URL and it should work the same way as normal HTTP urls.
So, how is the right way? i need to send credentials of users from my iOS app to my server to authenticate them, so i need to protect this credentials with the HTTPS.
My server already works fine with the HTTPS using internet browsers.
So far what i have is this:
NSString *user = @"user";
NSString *pass = @"pass";
NSString *postData = [NSString stringWithFormat:@"user=%@&pass=%@", user, pass];
NSURL *url = [NSURL URLWithString:@"https://myserver.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
request.HTTPBody = [postData dataUsingEncoding:NSUTF8StringEncoding];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *strData = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"data %@", strData);
}];