为什么我更喜欢ASIHTTPRequest而不是NSURLConnection从web下载文件呢?

时间:2021-01-16 19:31:20

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

我曾多次看到有人使用ASIHTTPRequest来下载文件。现在我想知道为什么?NSURLConnection的核心优势是什么?

4 个解决方案

#1


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;

    ASIHTTPRequest允许为每个请求指定一个委托(对整个NSURLConnection指定一个委托);这很有用,因为每个请求在得到等待的数据后,原则上都有不同的处理;

  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;

    ASIHTTPRequest支持一种缓存机制,使应用程序在脱机时能够非常容易地工作(并显示缓存的数据);NSURLRequest中没有这种机制;

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

    如果您搜索*,您将会发现许多关于NSURLConnection/NSURLRequest引发的非常奇怪的内存泄漏的提示;这在ASIHTTRequest中没有经验;

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

    ASIHTTRequest提供了更好的可及性实现,这是绝对必要的;苹果提供了一个据说是童车。

Hope this helps.

希望这个有帮助。

#2


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.

ASIHTTPRequest更容易使用。您不必手动连接数据块,POST请求很容易构建,块是受支持的,ASIHTTPRequest是NSOperation的子类,因此您可以轻松地对请求进行排队,等等。

#3


4  

ASIHTTPRequest's strength points are IMHO:

ASIHTTPRequest的优点是:

  • easy to use
  • 易于使用的
  • file posting
  • 文件上传
  • built-in authentication
  • 内置的验证
  • built-in zlib compression
  • 内置zlib压缩
  • queing
  • 那些排队

#4


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.

在文件范围之外,使用ASI处理响应委托必须比在NSURL类中构建的更容易。

#1


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;

    ASIHTTPRequest允许为每个请求指定一个委托(对整个NSURLConnection指定一个委托);这很有用,因为每个请求在得到等待的数据后,原则上都有不同的处理;

  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;

    ASIHTTPRequest支持一种缓存机制,使应用程序在脱机时能够非常容易地工作(并显示缓存的数据);NSURLRequest中没有这种机制;

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

    如果您搜索*,您将会发现许多关于NSURLConnection/NSURLRequest引发的非常奇怪的内存泄漏的提示;这在ASIHTTRequest中没有经验;

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

    ASIHTTRequest提供了更好的可及性实现,这是绝对必要的;苹果提供了一个据说是童车。

Hope this helps.

希望这个有帮助。

#2


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.

ASIHTTPRequest更容易使用。您不必手动连接数据块,POST请求很容易构建,块是受支持的,ASIHTTPRequest是NSOperation的子类,因此您可以轻松地对请求进行排队,等等。

#3


4  

ASIHTTPRequest's strength points are IMHO:

ASIHTTPRequest的优点是:

  • easy to use
  • 易于使用的
  • file posting
  • 文件上传
  • built-in authentication
  • 内置的验证
  • built-in zlib compression
  • 内置zlib压缩
  • queing
  • 那些排队

#4


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.

在文件范围之外,使用ASI处理响应委托必须比在NSURL类中构建的更容易。