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