I am creating a network queue to send two requests.I have added these two request in network queue.
-(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];
}
}
For checking my responce i am getting the responce in
requestFinished:(ASIHTTPRequest *)request methode,
it always shows the first xml data as responce(NSLog(@”%@”,responseString);),
if i change my key from requestnum to requestnum1 i get the first xml data as responceString,why i am not able to access the second request’s responce.
-(void)requestFinished:(ASIHTTPRequest *)request
{
NSString *str ;
str= [request.userInfo objectForKey:@"requestnum1"];
NSString *responseString = [request responseString];
str = [request responseString];
NSLog(@"%@",responseString);
}
Its very simple to differentiate both request. Just assign tag to each request.
In request finish handle accordingly
Enjoy.