以下有兩種方式可以獲取響應的數據流
1. 接收端通過Request.InputStream讀取流
public static string StreamRead()
{
byte[] byts = new byte[HttpContext.Current.Request.InputStream.Length];
HttpContext.Current.Request.InputStream.Read(byts, 0, byts.Length);
string req = System.Text.Encoding.UTF8.GetString(byts);
return HttpContext.Current.Server.UrlDecode(req);
}
2.
/// <summary>
/// 獲得請求報文轉換成字符串
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string getRequestBody(HttpRequestBase request)
{
string result = "";
using (Stream st = request.InputStream)
{
StreamReader sr = new StreamReader(st, Encoding.UTF8);
result = sr.ReadToEnd();
}
return result;
}