上下文:我的应用程序位于中央登录应用程序后面,每当用户申请访问我的应用程序时,我的应用程序都会收到一个包含用户信息的 http 请求。我需要从 HttpRequest 正文中检索用户信息。
这是我到目前为止所尝试的:
currentContext.HttpContext.Request.Query["user-name"].toString(); // got nothing
using (var reader = new StreamReader(currentContext.HttpContext.Request.Body))
{
var body = reader.ReadToEnd();
} // I can get the raw HttpRequest Body as "user-name=some&user-email=something"
有什么方法可以用来解析 Request.Body 中的参数和值吗?我尝试了以下,也一无所获。
HttpContext.Item['user-name'] \\return nothing
Request.Form["user-name"] \\ return nothing
我无法使用模型绑定的原因是,在 HttpRequest 正文中,键名是“用户名”,而在 c# 中,我无法创建带有“-”的变量
同时,在我的 .net 4.6 应用程序中,Request["KeyName"].toString()工作得很好。
白衣非少年
慕尼黑5688855
狐的传说
随时随地看视频慕课网APP
相关分类