title: NSURLSession for sending multiple images by multiple urls
body: <p>The below code i am using for sending multiple images along with the text. but only one image is saving in Web server. Here the problem is i need to get response from the first url and i've to assign it to the second url.</p>
  
  <pre><code>NSLog(@"PassedID%@",PassedUserId);
  
  NSLog(@"integer=%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"Person"]);
  
  
  NSString *CategoryId=@"3";
  NSString *imagename=@"ComparisonObject";
  
   NSString *requestString =[NSString stringWithFormat:@"UserId=%@&amp;CategoryId=%@&amp;Continent=%@&amp;Country=%@&amp;City=%@&amp;Gender=%@&amp;ImageName=%@",PassedUserId,CategoryId,continentTextfield.text,countrytextfield.text,citytextfield.text,GenderText.text,imagename];
    NSLog(@"%@",requestString);
  
  NSString *url=[NSString stringWithFormat:@"http://192.168.2.4:98/UserImage.svc/InsertObjectImage?%@",requestString];
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
  [request setURL:[NSURL URLWithString:url]];
  
  [request setHTTPMethod:@"POST"];
  
  NSURLSession *session = [NSURLSession sharedSession];
  NSURLSessionDataTask *uploadImage1 = [session dataTaskWithRequest:request completionHandler:^(NSData *data2, NSURLResponse *response, NSError *error) {
      // Finish uploading image 1
      // Get response and data to prepare to update image 2
  
      NSString *boundary = @"---------------------------14737809831466499882746641449";
      NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
      [request setValue:contentType forHTTPHeaderField:@"Content-Type"];
      NSData *data = UIImageJPEGRepresentation(chosenImage1, 0.2f);
      [request addValue:@"image/JPEG" forHTTPHeaderField:@"Content-Type"];
      NSMutableData *body = [NSMutableData data];
      [body appendData:[NSData dataWithData:data]];
      [request setHTTPBody:body];
  
  
      NSData *returnData;
      NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
  
  
      NSLog(@"recievedData%@",receivedData);
      NSString *imagename=@"ComparisonObject";
  
      NSString *requestString1 =[NSString stringWithFormat:@"UserId=%@&amp;ImageId=%@&amp;=ImageName%@",PassedUserId,compareId,imagename];
      NSLog(@"%@",requestString1);
  
      NSString *url=[NSString stringWithFormat:@"http://192.168.2.4:98/UserImage.svc/UpdateObjectImage?%@",requestString1];
  
      NSMutableURLRequest *request2 = [[NSMutableURLRequest alloc] init] ;
      [request setURL:[NSURL URLWithString:url]];
      [request setHTTPMethod:@"POST"];
  
      NSURLSessionDataTask *uploadImage2 = [session dataTaskWithRequest:request2 completionHandler:^(NSData *data1, NSURLResponse *response, NSError *error) {
  
  
          NSLog(@"recievedData%@",receivedData);
          NSString *imagename=@"ComparisonObject";
  
          NSString *requestString1 =[NSString stringWithFormat:@"UserId=%@&amp;ImageId=%@&amp;=ImageName%@",PassedUserId,compareId,imagename];
          NSLog(@"%@",requestString1);
  
          NSString *url=[NSString stringWithFormat:@"http://192.168.2.4:98/UserImage.svc/UpdateObjectImage?%@",requestString1];
  
          NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
          [request setURL:[NSURL URLWithString:url]];
          [request setHTTPMethod:@"POST"];
  
          NSString *boundary = @"---------------------------14737809831466499882746641449";
          NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
          [request setValue:contentType forHTTPHeaderField:@"Content-Type"];
          NSData *data = UIImageJPEGRepresentation(chosenImage2, 0.2f);
          [request addValue:@"image/JPEG" forHTTPHeaderField:@"Content-Type"];
          NSMutableData *body = [NSMutableData data];
          [body appendData:[NSData dataWithData:data]];
          [request setHTTPBody:body];
           NSData *returnData;
          NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
  
  
          // Finish uploading image 2
      }];
  
  }];
  </code></pre>