Skip to content

Instantly share code, notes, and snippets.

@daijo
Created September 2, 2011 01:21
Show Gist options
  • Save daijo/1187733 to your computer and use it in GitHub Desktop.
Save daijo/1187733 to your computer and use it in GitHub Desktop.
Add basic auth credential for a NSURLConnection.
NSURLCredentialStorage *sharedCredentials = [NSURLCredentialStorage sharedCredentialStorage];
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user" password:@"pwd" persistence:NSURLCredentialPersistencePermanent];
NSURLProtectionSpace *protectionSpace = [[[NSURLProtectionSpace alloc] initWithHost:@"my.gtdify.com" port:80 protocol:@"http" realm:nil authenticationMethod:NSURLAuthenticationMethodHTTPBasic] autorelease];
[sharedCredentials setCredential:credential forProtectionSpace:protectionSpace];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment