-1

i've working on the below code to send image to web server. its working fine. i need to run two urls at time with single NSMutableURLRequest.

  NSString *requestString =[NSString stringWithFormat:@"UserId=%@&CategoryId=%@&Continent=%@&Country=%@&City=%@&Gender=%@&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"];

// Create 'POST' MutableRequest with Data and Other Image Attachment.

NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
NSData *data = UIImageJPEGRepresentation(chosenImage2, 0.1f);
[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(@"Ret: %@",returnString);
GPR
  • 91
  • 9
  • What do you mean "run two URLs with `NSMUtableURLRequest`"? That doesn't quite make sense. Are you trying to upload two images in a single `multipart/form-data` request? Regardless, the above `multipart/form-data` request is not well formed. Have you considered using AFNetworking, which takes care of the construction of multipart requests for you? – Rob Jun 16 '14 at 13:33

1 Answers1

1

You said

I need to run two urls at time with single NSMutableURLRequest.

As far as I know that's not possible.

When you submit an URL request, you do it with an NSURLConnection or NSURLSession. Those can manage each request separately and asynchronously.

Just create 2 requests and submit them separately. You then need to keep track of the responses separately, but it's pretty easy to do so.

Duncan C
  • 128,072
  • 22
  • 173
  • 272