• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Force authentication with NSURLConnection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Force authentication with NSURLConnection
      • From: Dave Dribin <email@hidden>
References: 
 >Force authentication with NSURLConnection (From: Dave Dribin <email@hidden>)

  • Prev by Date: Re: slide nsimage
  • Next by Date: Embeding a view into another application
  • Previous by thread: Re: Force authentication with NSURLConnection
  • Next by thread: Re: Force authentication with NSURLConnection
  • Index(es):
    • Date
    • Thread