我有一个函数返回每个请求的请求参数:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用GET和POST调用相同的url时,$ _POST参数为空.我使用WizTools RestClient和XAMPP工具中的Apache Server来调用以下url:
http://localhost:80/project/?item=1
对于GET,请求参数正确包含"item",但对于POST,请求参数为空.
似乎post方法被正确检测为以下函数,正确发送到postDescription()方法:
$method = strtolower($_SERVER['REQUEST_METHOD']) . 'Description';
我找到了一个信息来编辑php.ini post_max_size = 8*M*到8*MB*但这对我没有用.
$_GET 使用URL的查询字符串中的数据填充.
$_POST填充了帖子消息正文中的数据.
如果你犯了一个职位的要求,但在查询字符串传递数据,然后将数据就会出现在$_GET不$_POST.