Skip to content

Instantly share code, notes, and snippets.

@vkoser
Created March 3, 2010 01:57
Show Gist options
  • Save vkoser/320218 to your computer and use it in GitHub Desktop.
Save vkoser/320218 to your computer and use it in GitHub Desktop.
// dataStr is a base64 encoded username and password in format username:password
NSMutableString *dataStr = @"Basic dXNlcm5hbWU6cGFzc3dvcmQ=";
// Set up the URL
NSMutableURLRequest * request=(NSMutableURLRequest*)[NSMutableURLRequest requestWithURL:[NSURL URLWithString:theURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1.0];
// append the http header for authentication
[request addValue:dataStr forHTTPHeaderField:@"Authorization"];
// Send the request to the web service
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment