title: How to keep a connection alive using ASIHTTP? I need to make multiple requests, but can't afford to open, then close a request connection
body: <p>I have a method that I call to make web service requests using GET. It looks like this:</p>
  
  <pre><code>- (UIImage*)getImageWithSeriesGUID:(NSString*)seriesGUID ImageID:(int)imageID {
  
  NSString * unescapedString = RIVERWOODS_GET_IMAGE(seriesGUID, imageID);
  
  NSURL *url = [[NSURL alloc] initWithString:[unescapedString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
  
  
  ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
  
  [request setRequestMethod:@"GET"];
  [request addRequestHeader:@"Connection" value:@"Keep-Alive"];
  
  [request startSynchronous];
  NSError *error = [request error];
  if (!error) {
      NSData *response = [request responseData];
      //NSLog(@"Size: %@",[response length]);
      NSString *content = [[[NSString alloc] initWithData:response
                                                 encoding:NSUTF8StringEncoding] autorelease];
      NSLog(@"Data: %@", content);
      UIImage *image = [UIImage imageWithData:response];
      return image;
  }
  
  return nil;
   }
  </code></pre>
  
  <p>This approach works ok, but it is just REALLY slowly. On the other end I am iterating through a for loop so this method gets called 20 times if the picture array I need to collect has 20 images. I am looking to improve the efficiency of this process, and I am thinking that I should be able to iterate through all the image Id's I need to collect right here in this method.</p>
  
  <p>It seems to me that the reason this goes so slowly is because the multiple requests that we keep opening and closing. THe images I am pulling in are on average ~15kb.</p>
  
  <p><strong>My question:</strong> What can I do to change this method around to make it so I can improve efficiency and take advantage of the HTTP keep-alive features? I am thinking that instead of passing in an image ID, I can just pass in the count of the array I need to make, and then setup a for-loop of some sorts here in the request method which would then allow me to pass back an array of images...</p>
  
  <p>Is that the way to go? Is there something I am missing? I appreciate your help and input!!</p>