Re: Force authentication with NSURLConnection
Re: Force authentication with NSURLConnection
- Subject: Re: Force authentication with NSURLConnection
- From: "Stephen Deken" <email@hidden>
- Date: Fri, 16 Mar 2007 13:02:40 -0500
On 3/12/07, Dave Dribin <email@hidden> wrote:
Is there any way to override the
authentication tell NSURLConnection to use basic auth without the
delegate method?
In your NSURLRequest, you should be able to add an HTTP header with
the required Authorization header. The format is pretty simple: the
string "Basic " followed by a base-64 encoding of the username and
password, separated by a colon. Something like this:
NSString *username = ...;
NSString *password = ...;
NSURLRequest *req = ...;
NSString *tmp = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *data = [[NSData dataWithBytes:[tmp cString] length:[tmp
length]] encodeBase64];
[req addValue:[NSString stringWithFormat:@"Basic %@", tmp]
forHTTPHeaderField:@"Authorization"];
You'll need the category on NSData to get the 'encodeBase64' in order
to use this, though. I think you can find it out there on the web
somewhere. Some yahoo named Dave wrote it. :)
http://www.dribin.org/dave/blog/archives/2006/03/12/base64_cocoa/
--
Stephen Deken
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden