Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASIHTTPRequest vs AFNetworking vs NSUrlRequest

In the past I have use ASIHTTPRequest but now there is NSURLRequest. Should we be using the NSURLRequest now? Are there any disadvantages?

For people reading this now: I ended up using AFNetworking as mentioned in the answers

https://github.com/AFNetworking/AFNetworking

Thanks,

like image 528
William Falcon Avatar asked Mar 30 '13 13:03

William Falcon


2 Answers

NSURLConnection and NSURLRequest are the provided Cocoa classes for managing connections. In iOS 7, Apple added NSURLSession.

But I think you'll find AFNetworking to be a framework that further simplifies network requests (notably complex HTTP requests). If you don't want to use third-party frameworks for any reason, you can use NSURLConnection and/or NSURLSession directly. It just takes a little more coding.

If you're looking for a good ASIHTTPRequest alternative, AFNetworking is a great candidate.

For information on NSURLConnection and NSURLSession see the URL Loading System Programming Guide.

like image 181
Rob Avatar answered Nov 17 '22 05:11

Rob


NSURLRequest has been there since iOS2.0 (see the doc), so it is not precisely new. ASIHTTPRequest has been discontinued, the last update was on 15th May 2011, so you shouldn't use it. AFNetworking is a delightful networking library for iOS and Mac OS X as described by them self, and really makes your live easier, in my case it is the first framework I include in my network required projects.

Which one you should use?, I think this depends on your requirements, with NSURLRequest and NSURLConnection you can do everything, in fact AFNetworking us built on top of NSURLConnection. But how I tell you before, AFNetworking has my upvote.

EDIT post iOS7

If you are targeting iOS7 you should take a look to NSURLSession, check the official documentation, and this tutorial.

EDIT for Swift

Take a look to the Alamofire project for an implementation done in Swift, it is also created by mattt (the main author of AFNetworking).

like image 20
tkanzakic Avatar answered Nov 17 '22 05:11

tkanzakic