简体   繁体   English

如何从ASP.NET Web表单的HttpRequest主体读取数据

[英]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.

相关问题 如何在asp.net中制作httprequest正文 - How to make a httprequest body in asp.net 如何从ASP.NET MVC中的Web表单清除数据? - How to clean data from web forms in asp.net mvc? ASP.NET Web API无法从POST正文读取 - ASP.NET Web API unable to read from POST body 如何在ASP.NET Web表单中验证此数据输入表单? - How to validate this data entry form in ASP.NET Web Forms? 如何从asp.net C#Web窗体应用程序中的GridView中将selectedrow单元格值获取到电子邮件正文中? - How to get selectedrow cell value from a gridview into the body of an email in my asp.net c# web forms application? 如何从 asp.net web 表单中的 gridview 获取值? - how to get values from gridview in asp.net web forms? 如何将CKEditor中的RTF文本数据存储在ASP.NET Web窗体数据库中? - how to store rich text data from CKEditor in ASP.NET Web Forms database..? 如何显示从ASP.NET Web应用程序到Xamarin.Forms的数据? - How to show data from ASP.NET Web Application to Xamarin.Forms? 如何将ASP.NET Web窗体应用程序从成员身份迁移到ASP.NET Identity 2.0? - How to migrate ASP.NET Web Forms application from Membership to ASP.NET Identity 2.0? ASP.NET 如何在 Web API 中读取多部分表单数据? - ASP.NET How read a multipart form data in Web API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM