[英]How to read data from HttpRequest body in asp.net web forms
I have created a POST request with some credential information on Request body. 我创建了一个POST请求,并在Request主体上添加了一些凭据信息。
The below request details, I have captured from fiddler. 下面的请求详细信息,我是从提琴手那里捕获的。
Raw Data: 原始数据:
POST http://localhost/AutovhcReport/rdPage.aspx?&rdframeid=rdFrame3416d447-50ed-f635-ed09-cdcb201017ee HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 56
Cache-Control: max-age=0
Origin: null
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Cookie: ddllanguage=en-GB; ASP.NET_SessionId=j50rws53zw1wrf4pn0yqmeot; rdPanelExpanded_Table=True; rdTablePanelMenuExpanded=False; rdAllowRedo=False; rdAllowUndo=False
rdReport=SampleReport&rdembedded=true&rdUserName=Dynamic
How to read the body values in Asp.net web forms C# ? 如何在Asp.net Web窗体C#中读取正文值?
I have tried this, LoginPage.aspx 我已经尝试过了,LoginPage.aspx
<%@ Page Language="c#" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e)
{
string username= HttpContext.Current.Request.Form["rdUserName"].ToString();
Session.Add("rdUserName",username);
Session.Add("SiteCode", "7");
Session.Add("UserName", "xxx");
Session.Add("Password", "xxxxx");
HttpContext.Current.Response.Redirect("rdPage.aspx");
}
</script>
In ASP.NET web forms there are objects that holds all the http data. 在ASP.NET Web表单中,存在保存所有http数据的对象。 So in the desired event handler just read values by key
因此,在所需的事件处理程序中,只需按键读取值
string val = Request.Form["rdReport"]
or iterate array 或迭代数组
Request.Form[]
Request.Form["key"]
should work. Request.Form["key"]
应该可以工作。 Alternatively you can try Request.Form[index]
Here is my sample code: 另外,您可以尝试
Request.Form[index]
这是我的示例代码:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Request.HttpMethod.ToString() + "<br/>");
if (Request.HttpMethod == "POST")
{
if (Request.Form.Count > 0)
{
Response.Write(Request.Form[0] +"<br/>");
Response.Write(Request.Form[1] + "<br/>");
Response.Write(Request.Form[2] + "<br/>");
}
}
}
Here is a screenshot from fiddler : 这是fiddler的屏幕截图:
Looks like you need to debug your app to see where the failure might be. 看来您需要调试您的应用程序才能查看失败的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.