我正在创建一个网络队列来发送两个请求。我已将这两个请求添加到网络队列中。
-(void)viewDidLoad
{
[super viewDidLoad];
ASINetworkQueue *networkQueue = [[ASINetworkQueue queue] retain];
NSURL *url = [NSURL URLWithString:@"http://www.w3schools.com/xml/simple.xml"];
NSURL *url1 = [NSURL URLWithString:@"http://search.twitter.com/search.json?q=mobtuts&rpp"];
for(int i = 0; i<=1; i++)
{
if(i==0)
{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
NSString *str =[NSString stringWithFormat: @"%d", i];
request.userInfo = [NSDictionary dictionaryWithObject:str forKey:@"requestnum"];
[request setDelegate:self];
[networkQueue addOperation:request];
}
if(i==1)
{
ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1];
NSString *str =[NSString stringWithFormat: @"%d", i];
request1.userInfo = [NSDictionary dictionaryWithObject:str forKey:@"requestnum1"];
[request1 setDelegate:self];
[networkQueue addOperation:request1];
}
[networkQueue go];
}
}
为了检查我的响应,我在 requestFinished:(ASIHTTPRequest *)request 方法中得到响应,如果我将密钥从 requestnum 更改为requestnum1 我将第一个 xml 数据作为响应字符串获取,为什么我无法访问第二个请求的响应。
-(void)requestFinished:(ASIHTTPRequest *)request
{
NSString *str ;
str= [request.userInfo objectForKey:@"requestnum1"];
NSString *responseString = [request responseString];
str = [request responseString];
NSLog(@"%@",responseString);
}