Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a POST variable

I am using C# with ASP.NET.

How do I check if a parameter has been received as a POST variable?

I need to do different actions if the parameter has been sent via POST or via GET.

like image 822
user261863 Avatar asked Jan 29 '10 14:01

user261863


People also ask

How do you get a post variable?

The variable $_POST is automatically populated. Try var_dump($_POST); to see the contents. If your post data is in another format (e.g. JSON or XML, you can do something like this: $post = file_get_contents('php://input');

What is a post variable?

The $_POST variable is an array of variable names and values sent by the HTTP POST method. The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

What is the purpose $_ GET and $_ post variable?

Use of $_ GET and $_ POST in PHP. $_GET, and $_POST are array variables of PHP which are used to read submitted data by HTML form using the get and post method accordingly.


2 Answers

Use this for GET values:

Request.QueryString["key"] 

And this for POST values

Request.Form["key"] 

Also, this will work if you don't care whether it comes from GET or POST, or the HttpContext.Items collection:

Request["key"] 

Another thing to note (if you need it) is you can check the type of request by using:

Request.RequestType 

Which will be the verb used to access the page (usually GET or POST). Request.IsPostBack will usually work to check this, but only if the POST request includes the hidden fields added to the page by the ASP.NET framework.

like image 117
Dan Herbert Avatar answered Sep 22 '22 05:09

Dan Herbert


Use the

Request.Form[]

for POST variables,

Request.QueryString[]

for GET.

like image 25
egyedg Avatar answered Sep 20 '22 05:09

egyedg