首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >对php的POST请求仅出现在$_GET变量中

对php的POST请求仅出现在$_GET变量中
EN

Stack Overflow用户
提问于 2014-11-18 04:23:33
回答 2查看 114关注 0票数 1

我发送帖子数据到一个php页面,并通过var_dump($_POST)接收它。但是,$_POST始终为空,并且$_GET包含这些值。我确信这是一个POST请求,并且已经在Postman REST客户端和cURL中进行了测试。我使用的是PHP 5.5.3和Apache 2.2。谢谢

编辑:我正在使用php脚本作为api,所以目前我正在使用上面提到的工具进行测试,以使用POST测试请求。例如,我使用这个cURL请求curl -X POST http://dev/project/build/api/registrants.php?hello=there

my $_SERVER的内容(在区域中编辑)

array(25) {
  ["HTTP_USER_AGENT"]=>
  string(11) "curl/7.37.1"
  ["HTTP_HOST"]=>
  string(3) "dev"
  ["HTTP_ACCEPT"]=>
  string(3) "*/*"
  ["PATH"]=>
  string(29) "/usr/bin:/bin:/usr/sbin:/sbin"
  ["SERVER_SIGNATURE"]=>
  string(0) ""
  ["SERVER_SOFTWARE"]=>
  string(67) "Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8za DAV/2 PHP/5.5.3"
  ["SERVER_NAME"]=>
  string(3) "dev"
  ["SERVER_ADDR"]=>
  string(9) "127.0.0.1"
  ["SERVER_PORT"]=>
  string(2) "80"
  ["REMOTE_ADDR"]=>
  string(9) "127.0.0.1"
  ["DOCUMENT_ROOT"]=>
  string(25) "/Applications/MAMP/htdocs"
  ["SERVER_ADMIN"]=>
  string(15) "you@example.com"
  ["SCRIPT_FILENAME"]=>
  string(59) "/Applications/MAMP/htdocs/project/build/api/registrants.php"
  ["REMOTE_PORT"]=>
  string(5) "51096"
  ["GATEWAY_INTERFACE"]=>
  string(7) "CGI/1.1"
  ["SERVER_PROTOCOL"]=>
  string(8) "HTTP/1.1"
  ["REQUEST_METHOD"]=>
  string(4) "POST"
  ["QUERY_STRING"]=>
  string(10) "hello=there"
  ["REQUEST_URI"]=>
  string(45) "/project/build/api/registrants.php?hello=there"
  ["SCRIPT_NAME"]=>
  string(34) "/project/build/api/registrants.php"
  ["PHP_SELF"]=>
  string(34) "/project/build/api/registrants.php"
  ["REQUEST_TIME_FLOAT"]=>
  float(1416256385.03)
  ["REQUEST_TIME"]=>
  int(1416256385)
  ["argv"]=>
  array(1) {
    [0]=>
    string(10) "hello=there"
  }
  ["argc"]=>
  int(1)
}
EN

回答 2

Stack Overflow用户

发布于 2014-11-18 04:24:44

<form>标记中,确保存在method="POST"属性。

票数 0
EN

Stack Overflow用户

发布于 2018-07-10 22:28:13

嗯,我也有同样的问题,我发现错误是我使用了错误的头,变量应该在请求的主体中传递,而不是作为URL参数传递。我使用Postman来生成POST请求,并且填充了$_GET和$_POST ( $_POST (0)),所以我读到了有关应用程序超全局的信息,并且只有在请求中使用应用程序/x-www-form-urlencoded或multipart/form-data作为HTTP Type时才会填充,根据Postman:http://php.net/manual/en/reserved.variables.post.php。然后,我阅读了Postman手册,它在打印屏幕上显示参数必须在正文中,就像在会话请求正文中解释的那样:https://www.getpostman.com/docs/v6/postman/sending_api_requests/requests。正如steve在他对你的问题的评论中所说的那样,使用curl这个请求应该是这样的格式:

curl -X POST --data "param1=value1&param2=value2" https://example.com/resource.cgi
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26981275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档