Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good HTTP library for Objective-C / iPhone? [closed]

UPDATE: this question is obviously obsolete (see the date). I recommend just using modern iOS7 features like NSURLSession. The question is preserved for historical accuracy, I guess.

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.

like image 988
Jaanus Avatar asked Jan 14 '10 02:01

Jaanus


4 Answers

Check out All Seeing Interactives ASIHTTPRequest library

like image 154
justinlatimer Avatar answered Nov 11 '22 23:11

justinlatimer


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...

like image 36
Dave DeLong Avatar answered Nov 11 '22 23:11

Dave DeLong


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.

like image 1
Garrett H Avatar answered Nov 11 '22 22:11

Garrett H


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).

like image 1
ImHuntingWabbits Avatar answered Nov 11 '22 22:11

ImHuntingWabbits