gpt4 book ai didi

iphone - ASIHTTPRequest 上的多个请求

转载 作者:太空狗 更新时间:2023-10-30 03:39:58 26 4
gpt4 key购买 nike

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

现在 ASIHTTPRequest 网站上的异步请求示例显示如下:

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

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

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

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

这个方法如何区分不同的请求,以便我可以不同地处理它?<​​/p>

谢谢,

最佳答案

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

  • 设置请求的userInfo字典
  • 将 didFinishSelector(和 didFailSelector 等)设置为不同的方法
  • 使用不同的类作为委托(delegate)
  • 使用积木
  • 使用请求的标签属性
  • 子类 ASIHTTPRequest 并覆盖覆盖 requestFinished: 和 failWithError:(仅推荐用于复杂情况)

关于iphone - ASIHTTPRequest 上的多个请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6571947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com