.net 用aspx作接口接收postman的訪問數據(json)

webservice.asmx   是用xml作爲底層傳輸數據的格式

碰到那種一定要求使用json格式的情況就比較麻煩

可以用aspx響應請求(效率不是很好,畢竟是頁面類型)

 

string postString = string.Empty;
            if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
            {
                using (Stream stream = HttpContext.Current.Request.InputStream)
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    Byte[] postBytes = new Byte[stream.Length];
                    stream.Read(postBytes, 0, (Int32)stream.Length);
                    postString = Encoding.UTF8.GetString(postBytes);

                }
                if (!string.IsNullOrEmpty(postString))
                {
                    Response.Write(postString);
                    Response.End();
                }
            }
            else
            {
                HttpContext.Current.Response.Clear();
                Response.Write("error");
                Response.End();
            }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章