【发布时间】:2018-07-11 04:15:48
【问题描述】:
我将 POST 数据发送到一个 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
我的 $_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)
}
【问题讨论】:
-
如果这是一个问题,需要查看一些代码
-
问题是什么?我们将查看您的发送方式以帮助您解决此问题。
-
客户端和服务器之间会不会有一些愚蠢的代理?
-
您正在发送发布请求,但您并未发送请求正文。
-
取决于您的客户,但对于 curl:superuser.com/questions/149329/…