discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Basic HTTP Authentication with Objective-C


From: Niels Grewe
Subject: Re: Basic HTTP Authentication with Objective-C
Date: Tue, 13 Aug 2013 14:52:32 +0000


Am 13.08.2013 um 15:52 schrieb Andreas Höschler <ahoesch@smartsoft.de>:

Hi all,

I need an Objective-C (GNUstep) wrapper for accessing the OpenStreetMap API, basically an Objective-C replacement for 

curl -v -H 'Authorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk' 'http://api.openstreetmap.org/path'

I do successfully access the API for read only calls that do not require authentication like so

   #define IPADDRESS @"api.openstreetmap.org"

   SRFileHandle *handle = [[SRFileHandle alloc] initAsClientAtAddress:IPADDRESS port:80];
   NSString *request = @"GET /api/capabilities\n";
   [handle writeData:[request dataUsingEncoding:NSUTF8StringEncoding]];
   NSData *data = "" readDataToEndOfFile];
   NSString *xmlString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
   [handle closeFile];
   [handle release];

   NSLog(@"xmlString: %@", xmlString);

Any idea how this could be extended to include Basic HTTP Authentication for PUT calls like 

PUT /api/0.6/changeset/create

Googling got me lots of NSURL, addRequestHeader,... stuff, but I don't have all these fancy new classes in my (rather old) GNUstep tree. Anyone?

I'd go with NSURLConnection and a NSMutableURLRequest that you set the authentication header using -setValue:forHTTPHeaderField:. If it's not in your GNUstep tree, that would indicate that it is pretty ancient, svn tells me that it been there since 2006, so it should really work. I think you should also be able to use the NSURLAuthenticationChallenge/NSURLCredential stuff, but I've not used it on GNUstep recently.

Cheers,

Niels

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail


reply via email to

[Prev in Thread] Current Thread [Next in Thread]