获取webapi接口中的body内容
//声明http对象
HttpRequest request = HttpContext.Current.Request;
//获取http中body流
Stream reqStream = request.InputStream;
//声明StringBuilder 对象用来存储需要的字符串
StringBuilder builder = new StringBuilder();
using (MemoryStream ms = new MemoryStream())
{
//copy以进行后续读取,否则InputStream将被释放
request.InputStream.CopyTo(ms);
ms.Seek(0, SeekOrigin.Begin);
//读取字节流设置字节编码
using (StreamReader sr = new StreamReader(ms, Encoding.UTF8))
{
builder.Append(sr.ReadToEnd());
}
}