ASP.NET获取POST提交过来的数据流,转换成Json格式的字符串

时间:2021-01-06 15:01:37
 public class Public
{
private static Public _instance = new Public(); /// <summary>
/// 全局访问点
/// </summary>
public static Public Instance
{
get
{
return _instance;
}
} /// <summary>
/// 解析post流数据
/// </summary>
/// <returns></returns>
public string ShowUrlPostData()
{
try
{
Stream s = HttpContext.Current.Request.InputStream;
byte[] result_byte = new byte[];
MemoryStream ms = new MemoryStream();
int count = s.Read(result_byte, , result_byte.Length);
while (count != )
{
ms.Write(result_byte, , count);
count = s.Read(result_byte, , result_byte.Length);
}
string json_result = HttpUtility.UrlDecode(Encoding.UTF8.GetString(ms.ToArray())).Trim('=');
return json_result;
}
catch { }
return "";
}
}