views:

2267

answers:

3

Hi guys, 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

//call sites, so we can confirm username and password and site/sites
NSURL *url = [NSURL URLWithString: urlbase];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setUsername:@"doronkatz%40xx.com" ];
[request setPassword:@"xxx"];

Where urlbase is a url to a REST site.

Now, a developer has told me there might be an issue or bug with this framework, and its not passing headers correctly. Is there another way of testing or accessing with authentication a network REST location?

+3  A: 

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.

paulthenerd
+1  A: 

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.

Ramin
Hi Ramin ive tried using the ASIHTTPRequest, even with the Twitter api to see if i can get a header thing to work, using addRequestHeader and using HTTPScoop but it does not show that headers are being passed to it.
Doron Katz
Which headers are you looking for? And when you hit the same URL with the browser, are you getting what you're looking for in HTTPScoop? If you are getting headers from browser but not in ASIHTTP, then you might want to file a bug report with the developer.
Ramin
Well for either of the sites im working on, with HTTPSchool im getting a response saying authentication needed. With Twitter, i can put the username and password in URL file, but when i put it as addRequestHeader HTTPSchoop doesnt show that i had put any headers. Thats why im wondering there must be something with ASIHTTP.
Doron Katz
ASIHTTP does support basic username/password authentication using the API you list. I don't think you need to add any extra headers unless it's a custom authentication scheme. I suggest you repost your question to their Google group for specific help: http://groups.google.com/group/asihttprequest
Ramin
+1  A: 

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.

petert