ASIHTTPRequest上的多个请求 [英] Multiple Requests on ASIHTTPRequest

查看:91
本文介绍了ASIHTTPRequest上的多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从三个不同的网址下载三组不同的数据。我决定使用ASIHTTPRequest。其中两个URL是我需要解析的JSON提要,其中一个是我需要在本地存储的.txt文件。

I need to download three different sets of data from three different URLs. I decided to use ASIHTTPRequest. Two of the URLs are JSON feeds which I need to parse and one of them is a .txt file online that I need to store locally.

现在是示例ASIHTTPRequest的异步请求网站显示以下内容:

Now the example that is on ASIHTTPRequest's website for an asynchronous request shows the following:

- (IBAction)grabURLInBackground:(id)sender {
   NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
   ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
   [request setDelegate:self];
   [request startAsynchronous];
}

要传递多个网址,我可以在三个不同的网址上调用请求。但我不确定如何在 requestFinished 方法中处理它们。文档显示为:

To pass multiple URLs, I can call "request" on three different URLs. But I am not sure how I would handle them in the requestFinished method. The documentation shows it as:

- (void)requestFinished:(ASIHTTPRequest *)request {
   // Use when fetching text data
   NSString *responseString = [request responseString];

   // Use when fetching binary data
   NSData *responseData = [request responseData];
}

这种方法如何区分不同的请求,以便我可以区别对待?

How would this method differentiate between different requests, so that I can handle it differently?

谢谢,

推荐答案

您可以区分不同的请求通过

You can differentiate between different requests by


  • 设置请求的userInfo字典

  • 设置didFinishSelector(和didFailSelector等)使用请求的标签属性

  • 使用不同的类作为委托

  • 使用块

  • 使用请求的标记属性
  • li>
  • 子类ASIHTTPRequest并覆盖覆盖requestFinished:和failWithError :(仅适用于复杂情况)

  • setting the userInfo dictionary of the request
  • setting the didFinishSelector (and didFailSelector etc.) to different methods
  • using different classes as delegate
  • using blocks
  • using the request's tag property
  • subclass ASIHTTPRequest and override override requestFinished: and failWithError: (only recommended for complex situations)

这篇关于ASIHTTPRequest上的多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆