Why should I prefer ASIHTTPRequest over NSURLConnection for downloading files from the web?

独自空忆成欢 提交于 2019-11-29 02:27:09

问题


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


回答1:


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.




回答2:


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.




回答3:


ASIHTTPRequest's strength points are IMHO:

  • easy to use
  • file posting
  • built-in authentication
  • built-in zlib compression
  • queing



回答4:


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.



来源:https://stackoverflow.com/questions/6143188/why-should-i-prefer-asihttprequest-over-nsurlconnection-for-downloading-files-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!