I am currently accessing a secure web server using the code below (which works fine) However is there a better way to do this where I just use the basic URL without adding the “uid” and “pwd” into the server address? I am not sure is this method keeps the uid/pwd secure?
NSString *dataURL = @"http://myUID:myPWD@parabolic.z7s.com/api/temps/r1/degc"
NSURL *url = [[NSURL alloc] initWithString:dataURL];
NSData *data = [NSData dataWithContentsOfURL:url];
Would I be better using NSURLConnection and doing this with the delegate callbacks?
Any pointers would be much appreciated …
If you’re doing this over HTTP, then either solution is insecure. Putting it in the URL is slightly worse, since URLs tend to be logged everywhere.
If you care about security, use HTTPS and a HTTP authentication mechanism (Basic is fine) which will keep the username/password from being evesdropped on the wire.
You can provide the authentication parameters using
didReceiveAuthenticationChallenge:anduseCredential: forAuthenticationChallenge:delegates on NSURLConnection.NSURLConnection isn’t that hard to use – and has the advantage of being asynchronous.