title: multipart/mixed in Iphone Application
body: <p>I am currently trying to send a multipart/mixed request in iphone application but the service is always returning the http status code 500. I don't have access to the source code of the webservice. In android the Registration Service is called like :</p>
  
  <pre><code>HttpPost httpost = new HttpPost(PlayerUrl.REGISTER_URL);
      httpost.setHeader("Content-Type", "multipart/mixed");
      MultipartEntity entity = new MultipartEntity();
  
      String jsonData = "{\"firstName\":\"abc\",\"lastName\":\"xyz\",\"email\":\"abc@xyz.com\",\"password\":\"abc\",\"inviteType\":\"1\"}";
  
      StringBody jsonBean = new StringBody(jsonData, "application/json", null);
  
      entity.addPart("user", jsonBean);
      entity.addPart("image", new FileBody(new File(
      "/data/face.png"), "face.png",
      "application/octet-stream", null));
  
      httpost.setEntity(entity);
  
      HttpResponse response = client.execute(httpost);
      System.out.println(response);
  </code></pre>
  
  <p>But, how to do that in iphone I have no idea. i searched for whole long day and could not achieve anything. I currently have the following code : </p>
  
  <pre><code> request = [[NSMutableURLRequest alloc] init];
      [request setURL:[NSURL URLWithString:url]];
      [request setHTTPMethod:method];
  
      //build body        
      NSMutableData *bodyForRequest = [NSMutableData data];
  
      //NSString *jsonData = [NSString stringWithFormat:@"%@", dataForJson];
  
      [request setHTTPMethod:@"POST"];
      NSString *boundary = @"91473780983146649988274664144";
      NSString *contentType = [NSString stringWithFormat:@"multipart/mixed; boundary=%@",boundary];
      [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
      [request addValue:@"1.0" forHTTPHeaderField: @"MIME-Version"];
  
      [bodyForRequest appendData:[[NSString stringWithFormat:@"If you can see this MIME than your client doesn't accept MIME types!\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  
  
  
      [bodyForRequest appendData:[@"Content-Type: application/json;name = \"user\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
      [bodyForRequest appendData:[@"Content-Transfer-Encoding: 7bit\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
      //[bodyForRequest appendData:[@"Content-ID: user\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
      //[bodyForRequest appendData:[[NSString stringWithFormat:@"Content-Disposition: name=\"user\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
  
  
  
      [bodyForRequest appendData:dataForJson];
  
      [bodyForRequest appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  
  
      [bodyForRequest appendData:[@"Content-Type: image/jpg; name=\"image\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
      [bodyForRequest appendData:[@"Content-Transfer-Encoding: base64\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
      //[bodyForRequest appendData:[@"Content-ID: image\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
      NSString *str=[NSString stringWithFormat:@"Content-Disposition: attachment ;file=\"image.jpg\";\r\n\r\n"];
  
      [bodyForRequest appendData:[[NSString stringWithString:str] dataUsingEncoding:NSUTF8StringEncoding]];
  
      [bodyForRequest appendData:[NSData dataWithData:dataForImage]];
  
  
      [bodyForRequest appendData:[[NSString stringWithFormat:@"--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
  
  
          [request setHTTPBody:bodyForRequest];
  
      // save request start time
      requestStartTime = [CNUtility currentTimeInMilliseconds];
  
      // _connection the request now
      NSLog(@"%@...request...%@",self,request);
      _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
      [_connection start];
  </code></pre>
  
  <p>my requirement is to send JSON data along with the profile Image to the server Please help me out or please do suggest me something that could help me.</p>
  
  <p>Also i am not permitted to use ASI so if there is something other than that please let me know.</p>