1

I am trying to send a smiley to server.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:tem="http://tempuri.org/"> 
<soapenv:Header/>
<soapenv:Body>
<tem:PostMessage>
<tem:UserID>1</tem:UserID>
<tem:FriendID>3</tem:FriendID>
<tem:Message>\ue415</tem:Message>
</tem:PostMessage>
</soapenv:Body>
</soapenv:Envelope> 

This is what I am posting to server. But server is getting Message as ?. So the other user also receives message as ? and not \ue415 which is smiley (:D).

halfer
  • 19,824
  • 17
  • 99
  • 186
Nitish
  • 13,845
  • 28
  • 135
  • 263
  • look [here](http://stackoverflow.com/q/3569648/971401). One of the answers suggests to send literally `:D` instead... –  Feb 27 '12 at 10:16
  • How does the server display the text? (is it html, are you looking at a debugger, is it a command line?) – nycynik Feb 29 '12 at 22:51

1 Answers1

1

\ue415 is the 16-bit character code, but your file specifies UTF-8 encoding—so you need to convert that character to the correct UTF-8 sequence. According to http://www.utf8-chartable.de/unicode-utf8-table.pl?start=58368 it's

ee 90 95

So, replacing \ue415 with \xee\x90\x95 will work if that's the correct format on the client side. If it's expecting HTML entities, it'd be &#xee;&#x90;&#x95; (or something like that).


One more thing: It just occurred to me that the emoji I've seen all take two characters in UTF-16. It turns out 0xE415 is an older-style emoji encoding (here's an SO post about it). The code for that emoji in the new unicode standard is 0x1f604, or in UTF-8:

F0 9F 98 84
Community
  • 1
  • 1
davehayden
  • 3,484
  • 21
  • 28
  • For F0 9F 98 84, what will be the string that is to be passed? – Nitish Mar 01 '12 at 04:26
  • \xNN is one way of formatting hexadecimal bytes in strings. (See "Strings and Non-ASCII Characters" in https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/strings/Articles/FormatStrings.html#//apple_ref/doc/uid/20000943-CJBEAEHH ) For example, [NSString stringWithUTF8String:@"\xF0\x9F\x98\x84"] returns an NSString with the smilie emoticon. The question is: What decoding steps are happening to your text before it goes to the server? Where is the text for that soap message coming from? Is it generated by your code? Is it in a text file? – davehayden Mar 01 '12 at 22:13
  • I am following no encoding steps for now. It is text coming from code. I have smileys as buttons whose title I am setting as **\ue415** and so on. I am passing these titles as message when user touches these buttons. – Nitish Mar 02 '12 at 03:56
  • Okay, understood. So you're appending button.titleLabel.text to an NSMutableString, or maybe creating the soap message with -[NSString stringWithFormat:], right? At some point, that string has to be converted to a sequence of bytes to go across the network. To do that correctly, you need to specify a string encoding; for example, to get an NSData from an NSString, you can use [string dataUsingEncoding:NSUTF8StringEncoding]. If you look in that NSData, you'll see that the smiley emoticon was converted to the UTF-8 sequence ee 90 95. …Or does that not jibe with what you're seeing? – davehayden Mar 02 '12 at 04:55