16

I've seen a couple of times people using ASIHTTPRequest to download files. Now I wonder why? What are the core benefits over NSURLConnection?

Proud Member
  • 40,078
  • 47
  • 146
  • 231
  • 2
    A year after this question, one should note that nowadays you should select AFNetworking instead of ASIHTTPRequest. – Till Sep 09 '12 at 13:38

4 Answers4

24

There are several reasons. In my mind these are the major ones:

  1. ASIHTTPRequest allows to specify a delegate for each request (vs. one delegate for a whole NSURLConnection); this is useful because each request has in principle a different processing once you get the data you were waiting for;

  2. ASIHTTPRequest supports a caching mechanism that make very easy to make your app working when offline (and showing the cached data); no such mechanism in NSURLRequest;

  3. If you search stackoverflow, you will find many hints at a very strange memory leak that NSURLConnection/NSURLRequest provoke; this is not experienced with ASIHTTRequest;

  4. ASIHTTRequest offers a better implementation of Reachability, which is absolutely necessary; the Apple provided one is said to be buggy.

Hope this helps.

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
  • +1 for mentioning the Reachability implementation and the leak issues of NSURLConnection/NSURLeRquest – Till May 26 '11 at 18:32
  • Sounds good. Very good. But what if Apple fixes the reachability detection bug - will ASIHTTPRequest stop working properly then? – Proud Member May 26 '11 at 19:25
  • @Mikhalo Ivanokov: no, because ASI Reachability is just a source file, no dependencies on Apple Reachability. – sergio May 26 '11 at 19:32
  • @sergio :- my app works fine for small pdfs when downloaded but it crashes when the pdf size is more than 2 MB. i have used NSURLConnection. Can u help me plz... – mAc Nov 14 '11 at 14:30
  • @mAc: I suspect that you are doing something incorrectly when receiving the data in the delegate. Anyway, I would suggest creating a specific question here on S.O., providing the relevant code, and you will find plenty of help... – sergio Nov 14 '11 at 14:34
  • ok i am adding a question and will provide u a link. will it be fine fr you... it will take 2 mins – mAc Nov 14 '11 at 14:36
  • http://stackoverflow.com/questions/8123294/my-app-crashes-when-downloading-large-pdfs-2mb-in-iphone ------ check this Que. – mAc Nov 14 '11 at 14:49
4

ASIHTTPRequest is just significantly easier to use. You don't have to concatenate data blocks manually, POST requests are easy to construct, blocks are supported, ASIHTTPRequest is a subclass of NSOperation so you can easily queue up your requests, etc.

kubi
  • 48,104
  • 19
  • 94
  • 118
  • my app works fine for small pdfs when downloaded but it crashes when the pdf size is more than 2 MB. i have used NSURLConnection. Can u help me plz... – mAc Nov 14 '11 at 14:31
  • http://stackoverflow.com/questions/8123294/my-app-crashes-when-downloading-large-pdfs-2mb-in-iphone ------ check this Que. – mAc Nov 14 '11 at 14:49
4

ASIHTTPRequest's strength points are IMHO:

  • easy to use
  • file posting
  • built-in authentication
  • built-in zlib compression
  • queing
Till
  • 27,559
  • 13
  • 88
  • 122
  • NSURLRequest has built in zlib compression – hooleyhoop Jul 01 '11 at 16:08
  • my app works fine for small pdfs when downloaded but it crashes when the pdf size is more than 2 MB. i have used NSURLConnection. Can anyone help me plz... – mAc Nov 14 '11 at 14:31
  • 1
    @mac you should really not hijack an answer with a new question hidden as a comment -> please post a new question on SO. – Till Nov 15 '11 at 00:39
  • Sry i have posted the question in the next answer of this Ques., u can go directly here : stackoverflow.com/questions/8123294/… ------ check this Que. – mAc Nov 15 '11 at 04:27
3

IMHO it comes down to ease of use for the programmer. It's very easy to work with and is incredibly well documented. You can very easily use queues and manage their status via delegation.

Outside the scope of files it is must easier to handle response delegation using ASI compared to the built in NSURL classes.

shawnwall
  • 4,549
  • 1
  • 27
  • 38