从ASP.NET中的POST方法检索数据

Eti*_*nne 32 c# vb.net asp.net methods postback

我正在使用ASP.NET.

有一个系统需要将数据发布到我的网站,他们要求的只是为我提供一个URL.所以我给了他们我的网址http://www.example.com/Test.aspx.

现在我不确切知道他们如何发布它但现在在我的Test.aspx页面上我需要编写将数据保存到数据库的代码.

但是我的Test.aspx页面如何工作以及我该怎么做?

我在我的页面加载事件中写了一些代码,它向我发送了一个关于页面加载的电子邮件,看看它们是否真的到达了页面,看起来它们甚至不是?

Adr*_*ode 38

来自请求的数据(内容,输入,文件,查询字符串值)都在此对象上HttpContext.Current.Request
读取发布的内容

StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream);
string requestFromPost = reader.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)

浏览所有输入

foreach (string key in HttpContext.Current.Request.Form.AllKeys)
{
   string value = HttpContext.Current.Request.Form[key];
}
Run Code Online (Sandbox Code Playgroud)


ipr*_*101 30

您可以使用与此类似的代码(C#)将页面值发布到页面 -

string formValue;
if (!string.IsNullOrEmpty(Request.Form["txtFormValue"]))
{
  formValue= Request.Form["txtFormValue"];
}
Run Code Online (Sandbox Code Playgroud)

或者这个(VB)

Dim formValue As String
If Not String.IsNullOrEmpty(Request.Form("txtFormValue")) Then
    formValue = Request.Form("txtFormValue")
End If
Run Code Online (Sandbox Code Playgroud)

获得所需的值后,就可以构造一个SQL语句并将数据写入数据库.