asp.net - REST WebService C# is not accepting Emoticons -
i have rest webservice accepts feedback windows 8.1 app. works until user inserts emoticon text.
example: awesome!! 😃
when happens get:{statuscode: 400, reasonphrase: 'bad request', version: 1.1, content: system.net.http.streamcontent, headers: { date: thu, 16 jul 2015 21:05:54 gmt server: microsoft-iis/10.0 x-powered-by: asp.net content-length: 1806 content-type: text/html }}
i have no idea why happening.
here code service:
[operationcontract] [webinvoke( method = "post", responseformat = webmessageformat.json, requestformat = webmessageformat.json, uritemplate = "postfeedback")] void capturefeedback(feedback tmpfeedback);
the processing code:
public void capturefeedback(feedback myfeedback) { using (dbemployeedirectoryentities entities = new dbemployeedirectoryentities()) { feedback tmpfeedback = new feedback(); tmpfeedback.feedbackguid = system.guid.newguid().tostring(); tmpfeedback.rating = myfeedback.rating; tmpfeedback.feedbackmessage = myfeedback.feedbackmessage; tmpfeedback.timestamp = myfeedback.timestamp; tmpfeedback.hostname = myfeedback.hostname; entities.feedbacks.add(myfeedback); entities.savechanges(); } }
the class:
public partial class feedback { public string feedbackguid { get; set; } public nullable<int> rating { get; set; } public string feedbackmessage { get; set; } public nullable<system.datetime> timestamp { get; set; } public string hostname { get; set; } }
i encoding request utf8:
httpresponsemessage myresponse = null;
var myclient = new httpclient(); myclient.baseaddress = new uri(baseaddress); var content = new stringcontent(myjson, encoding.utf8, "application/json"); try { myresponse = await myclient.postasync(myuri, content); return myresponse; } catch (exception ex) { throw ex; }
any ideas?
please check out:
https://en.wikipedia.org/wiki/utf-8
https://en.wikipedia.org/wiki/emoji
utf8 not support range emoji characters. you'll need utf32
https://msdn.microsoft.com/en-us/library/system.text.utf32encoding(v=vs.110).aspx
Comments
Post a Comment