title: HTTP POST fails when the body has emoji in it
body: <p>I am doing an HTTP POST for anything the user enters in uiTextField. The Text is captured in NSString which is then added to a NSDictionary. It then gets converted to a JSON and finally to NSData as UTF8 for the HTTP Body.</p>
  
  <p>This works perfectly if the user had entered plain text. However, if the user entered emoji then it works up till the point of the HTTP POST itself.</p>
  
  <p>The conversion from NSString to NSDict to JSON is all good. It even gets converted to NSData as UTF8. But when the POST is called it throws an error. Here is my code:</p>
  
  <p>It is actually occurring when I am trying to convert JSON to NSData (UTF8)  so I can pass it as HTTP Body for a POST I am making from my App to my backend. Here is the area where it throws an error:</p>
  
  <pre><code>NSString *jsonPushData = [self mutDictToJson:pushData];
  
  NSLog(@"sendMessage:jsonPushData has:  %@",jsonPushData);
  
  //NSData *requestBodyData = [NSData dataWithBytes:[jsonPushData UTF8String] length:[jsonPushData length]];
  
  NSData *requestBodyData = [NSData dataWithBytes:[jsonPushData UTF8String] length:[jsonPushData length]];
  
  
  NSMutableURLRequest *request =
  [[NSMutableURLRequest alloc] initWithURL: restApiUrl
                               cachePolicy: NSURLRequestUseProtocolCachePolicy
                           timeoutInterval: 10.0];
  
  
  NSLog(@"sendMessage:requestBodyData has: %@ with length: %lu",requestBodyData, [jsonPushData length]);
  
  [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  
  [request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[requestBodyData length]] forHTTPHeaderField:@"Content-Length"];
  
  [request setHTTPMethod: @"POST"];
  [request setHTTPBody: requestBodyData];
  
  returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
  </code></pre>
  
  <p>Here is the code in node.js:</p>
  
  <pre><code>// get all the insert (accessed at POST http://localhost:8080/api/insert)
   router.route('/sendMessage')
      .post(function(req, res) {
          console.log('-- Entered Send Message -- at:' + getDateTime());
          var message = req.body.message;
  
          console.log("tag is: " + req.body.tag + "   message is: "+message)
  
          azureNh.sendPushViaApns(req.body.tag, req.body.message);
  
      res.write("Response from Post function");
     res.end("end connection");
  
  });
  </code></pre>
  
  <p>When I send plain text, this works as expected. But when I send emoji from iphone via HTTP POST, it hits this method in node.js and immediately throws the following error: It does not event print the first line "--Entered sendMessage --":</p>
  
  <pre><code> SyntaxError: Unexpected end of input
      at Object.parse (native)
      at parse (/home/azureuser/node_modules/body-parser/lib/types/json.js:88:17)
      at /home/azureuser/node_modules/body-parser/lib/read.js:108:18
      at done (/home/azureuser/node_modules/body-parser/node_modules/raw-body/index.js:239:14)
      at IncomingMessage.onEnd (/home/azureuser/node_modules/body-parser/node_modules/raw-body/index.js:285:7)
      at IncomingMessage.g (events.js:199:16)
      at IncomingMessage.emit (events.js:104:17)
      at _stream_readable.js:908:16
      at process._tickCallback (node.js:355:11)
  </code></pre>
  
  <p>I get the POST is not prepared correctly to handle emojis. But I do not see any errors in Xcode for the POST attempt.</p>
  
  <p>I am lost with this, Please advice how to resolve this issue.</p>
  
  <p>Thanks in advance.</p>