How can you, in iOS, programmatically access a password protected site that has been protected by .htaccess or access control.
Using NSURLRequest, you can make a GET request from a URL. But if the URL is protected how would you send the username password pair. Also, what if it's encrypted with standard MD5 encryption.
Add something like this to your HTTPConnectionDelegate:
-(void)connection:(NSURLConnection *)aConnection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With