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.
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');
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.
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.
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.
Use the
Request.Form[]
for POST variables,
Request.QueryString[]
for GET.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With