以下有两种方式可以获取响应的数据流
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;
}
相关新闻
- 小程序登录流程图理解 2020-08-18
- 在C#中获取web.config中的配置信息 2021-08-23
- 小程序open-data头像样式 2021-04-10
- 小程序rich-text 富文本解析图片过大和图片路径的问题 2020-11-25
- C#中去掉字符串的最后一个字符 2020-11-23