views:

745

answers:

4

What's a good HTTP library for (desktop Cocoa and) iPhone? Should just have a good interface to the basics like HTTP headers, get/post values (request string creation, URL encoding/decoding), sync and async requests... preferably pure Obj-C implementation. NSURL* is somewhat lacking.

+7  A: 

Check out All Seeing Interactives ASIHTTPRequest library

justinlatimer
This and TTURLRequest both look neat.
Jaanus
+1  A: 

I've had great success with the Three20 Project's TTURLRequest. It's a genericized version of the UI Elements used in the Facebook App.

Garrett H
Is the official branch app-store safe yet?
Kendall Helmstetter Gelner
In http://three20.info/ there's an indicator of the current Three20 App Store status, and at the time of this writing it's marked "safe".
Adrian Kosmaczewski
+1  A: 

How about what's already built into Cocoa in the forms of NSURLRequest and it's subclass NSMutableURLRequest? You'll probably also get to use NSURLConnection along with it...

Dave DeLong
A: 

Setting the post parameters in the HTTP body is pretty straight forward with NSMutableURLRequest, you can wrap it in a convenience method via a category if that's more desirable, similar to the OAuth library on google code:

http://oauth.googlecode.com/svn/code/obj-c1/OAuthConsumer/NSMutableURLRequest+Parameters.m

Checkout the setParameters override, specifically these lines:


NSData *postData = [encodedParameterPairs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        [self setHTTPBody:postData];
        [self setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
        [self setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

Of course, you'll want to adjust the content-type header for the specific content of your post body (e.g. json, xml, etc).

ImHuntingWabbits