如何从NSURLConnection委托发送多个网址请求? [英] How can I send multiple url request from a NSURLConnection delegate?
本文介绍了如何从NSURLConnection委托发送多个网址请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的应用程序的逻辑流程:
This is the logical flow for my application:
-
首先,当视图控制器完成加载时,
NSURLConnection
请求可以开始执行
响应包含xml数据
在解析xml后,我需要发送另一个 NSURLConnection
请求。
After parsing that xml I need to send another NSURLConnection
request.
发送第二个请求后,如果响应正常,我会收到其他xml数据
After sending the second request, if the response is ok, I receive other xml data
解析第二个xml后,我必须检查一下第一个和第二个xml数据之间的问题。
After parsing the second xml, I have to check some issues between first and second xml data.
那么,是否可以发送多个请求?怎么样?我不需要代码,你可以解释一下。
So, is it possible to send multiple request? How? I do not need code, you could just explain it.
提前谢谢你。
推荐答案
- (void)viedDidLoad{
[super viewDidLoad];
[self firstRequestMethod];
}
- (void)firstRequestMethod{
NSString *myFirstRequestURL = @"<URL>";
NSURL *webURL = [NSURL URLWithString:myFirstRequestURL];
NSURLRequest *request = [NSURLRequest requestWithURL:webURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSError *error;
NSURLResponse *response;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(returnData)
{
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
//Parse your response here.
//Is desired response obtain call the second Request, as described above
if (TRUE) { //on success
[self secondRequestMethod];
}
}
}
- (void)secondRequestMethod{
NSString *mySecondRequestURL = @"<URL>";
NSURL *webURL = [NSURL URLWithString:mySecondRequestURL];
NSURLRequest *request = [NSURLRequest requestWithURL:webURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSError *error;
NSURLResponse *response;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(returnData)
{
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
//Parse your response here.
//Is desired response obtain call the second Request, as described above
if (TRUE) { //on success
//subsequent calls to other url, same as above
}
}
}
希望这会帮助你更好地理解....
Hope this will help you understand better....
这篇关于如何从NSURLConnection委托发送多个网址请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文