获取请求参数扩展

This commit is contained in:
陈淳
2022-09-29 18:01:19 +08:00
parent be7ea64c5a
commit 40dddb3316

View File

@@ -132,5 +132,24 @@ namespace Yi.Framework.WebCore
return "";
}
public static string GetRequestValue(this HttpContext context, string reqMethod)
{
string param;
if (HttpMethods.IsPost(reqMethod) || HttpMethods.IsPut(reqMethod))
{
context.Request.Body.Seek(0, SeekOrigin.Begin);
using var reader = new StreamReader(context.Request.Body, Encoding.UTF8);
//需要使用异步方式才能获取
param = reader.ReadToEndAsync().Result;
}
else
{
param = context.Request.QueryString.Value.ToString();
}
return param;
}
}
}