Reputation: 1368
I have a function that returns the request parameters for each request:
private function GetRequestParams() {
$method = $_SERVER['REQUEST_METHOD'];
switch (strtolower($method)) {
case 'put':
$this->requestParams = //parse_str(HttpResponse::getRequestBody())
$this->requestParams = array_map('urldecode', $this->requestParams);
break;
case 'post':
$this->requestParams = $_REQUEST;
break;
case 'get':
$this->requestParams = $_GET;
break;
case 'delete':
$this->requestParams = $_REQUEST;
break;
default:
$this->requestParams = $_REQUEST;
}
}
but when I call the same url with GET and POST, the $_POST parameters are empty. I use WizTools RestClient and the Apache Server from XAMPP tools to call the following url:
http://localhost:80/project/?item=1
For GET the request params correctly contain the "item", but for POST, the request params are empty.
It seems that the post method is correctly detected as the following function, sends correctly to postDescription() method:
$method = strtolower($_SERVER['REQUEST_METHOD']) . 'Description';
I have found an info to edit php.ini post_max_size = 8*M* to 8*MB* but that did not worked for me.
Upvotes: 0
Views: 1431
Reputation: 2718
$_POST is filled by HTML forms. If you have a form and use method="POST" then the results from the form will be placed in POST. Otherwise, if you use method="get" from forms OR use query strings (for example, index.php?foo=bar&this=that), then the results will be in $_GET.
Its generally safe to use $_REQUEST, however.
Upvotes: 1
Reputation: 44
First of all you should never use $_REQUEST as mentioned in some of the comments.
From http://php.net/manual/en/reserved.variables.request.php
Note: The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted. The presence and order of variables listed in this array is defined according to the PHP variables_order configuration directive.
And as Quentin already said in his answer, if you make a POST request the POST-Data has to be submitted in the body
From Wikipedia http://en.wikipedia.org/wiki/POST_(HTTP)
Name=Jonathan+Doe&Age=23&Formula=a+%2B+b+%3D%3D+13%25%21
Regards
Upvotes: 0
Reputation: 2732
I'm not quite understanding why you'd be checking for both to begin with, but $_GET
retrieves parameters sent in the URL (which is how you have it), whereas $_POST
retrieves data "posted" to the server... usually through a form of some kind.
What's your ultimate goal?
Upvotes: 0
Reputation: 943157
$_GET
is populated with data from the URL's query string.
$_POST
is populated with data from the post message's body.
If you make a post request but pass the data in the query string, then the data will appear in $_GET
not $_POST
.
Upvotes: 6