been wrestling with this for some time. I am trying to access a REST api on my iphone and came across the ASIHTTP framework that would assist me. So i did something like
I would recommend checking out RestKit: http://restkit.org/ It provides an excellent API for accessing RESTful web services and representing the remote resources as local objects, including persisting them to Core Data. HTTP authentication is supported out of the box.
I've used ASIHTTP in two apps so far and have had no problems.
Looks like you're doing HTTP Basic Auth with the remote site. Try hitting the same REST URL from a standard browser and pass the params you need down to it. It should prompt you for username/password. If it makes it through, then at least you know the server-side is set up to handle requests. If it doesn't, then you need to have a talk with the dev.
The next thing to try is put a Mac-based network sniffer and see what headers are going back and forth. Any of HTTPScoop, Wireshark, or Charles should work. Run the sniffer as a network proxy then run your app in the simulator and watch what goes across. Try it again with the browser. Once you see the differences, you can use the addRequestHeader
method on ASIHTTPRequest
to add any specific headers the server expects.
I have a couple of apps using a framework called Objective Resource which provides a wrapper for accessing remote REST based api's. It is aimed primarily at Ruby on Rails based applications so it's XML/JSON parsing may be tuned to handle some Rails defaults but it is worth looking at. It supports http basic authentication by default.
Just stumbled on this question - you might find LRResty pretty interesting as it uses NSOperation, blocks etc., see: GitHub for source (MIT license). I'm experimenting with it now - it has a sample app too.
I'm new to iOS development and I've been battling with some of the big frameworks listed on this page for the past month or so. It has been a nightmare. I'd honestly recommend you just stick to the basics and do it yourself using AFNetworking or Apple's own NSURLConnection.
One of the libraries listed is no longer maintained. Another underwent huge code-breaking API changes recently and now half of the tutorials describing its use no longer work. Others are massively bloated.
It's easier than you'd think. Some resources that helped me:
The examples on the AFNetworking homepage alone may get you 80% of the way there.
UPDATE: The Mantle Framework (open sourced by Github Inc.) is well-designed and easy to use. It handles object mapping: converting a JSON NSDictionary
to your own custom Objective-C model classes. It handles default cases sensibly and it's pretty easy to roll your own value transformers, e.g. from string to NSURL
or string to your custom enum
.