WebApi_返回Post格式数据

 

   [HttpPost]
        public HttpResponseMessage Post([FromBody] DingTalkCallBack bodyMsg, string signature, string timestamp, string nonce)
        {
            var checkCode = ISVCallbackProvider.Instance.ISVCallback(bodyMsg.encrypt, signature, timestamp, nonce);
            var result = toJson(checkCode);
            return result;
        }
        public static HttpResponseMessage toJson(Object obj)
        {
            String str;
            if (obj is String || obj is Char)
            {
                str = obj.ToString();
            }
            else
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                str = serializer.Serialize(obj);
            }
            HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
            return result;
        }

 

posted @ 2017-12-13 18:47  Coding_Yong  阅读(420)  评论(0编辑  收藏  举报