REST WebService C#不接受表情符号

时间:2015-07-16 21:20:18

标签: c# asp.net web-services rest iis

我有一个REST Web服务,可以接受来自Windows 8.1应用程序的反馈。一切都运行良好,直到用户在文本中插入表情符号。

示例:这太棒了!!

当发生这种情况时,我得到:{StatusCode:400,ReasonPhrase:'Bad Request',Version:1.1,Content:System.Net.Http.StreamContent,Headers: {   日期:星期四,2015年7月16日21:05:54 GMT   服务器:Microsoft-IIS / 10.0   X-Powered-By:ASP.NET   内容长度:1806   内容类型:text / html }}

我不知道为什么会这样。

以下是我的服务代码:

    [OperationContract]
    [WebInvoke(
        Method = "POST", 
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json,
        UriTemplate = "PostFeedback")]
    void CaptureFeedback(feedback tmpFeedback);

处理代码:

    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();
        }
    }

班级:

    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; }
    }

我将请求编码为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;
        }

有什么想法吗?

1 个答案:

答案 0 :(得分:0)