如何将POST数据传递给PHP-CGI? [英] How to pass POST data to the PHP-CGI?
问题描述
更新:
在绝望中,我在shell中执行了以下操作:
In a fit of desperation, I did the following in a shell:
REDIRECT_STATUS=true
SCRIPT_FILENAME=/var/www/...
REQUEST_METHOD=POST
GATEWAY_INTERFACE=CGI/1.1
export REDIRECT_STATUS
export SCRIPT_FILENAME
export REQUEST_METHOD
export GATEWAY_INTERFACE
echo "test=1" | php-cgi
...并且仍然没有 $ _ POST
变量显示在输出中:
...and STILL no $_POST
variables are showing up in the output of this:
<?php var_dump($_POST); ?>
我正在尝试创建一个接口的小型网络服务器使用 php-cgi
二进制文件。然而,情况并不顺利。 php-cgi
二进制文件正确处理GET请求。当涉及POST请求时, $ _ POST
数组为空,即使事情正在进行POST。
I am trying to create a small webserver that interfaces with the php-cgi
binary. However, things aren't going so well. The php-cgi
binary correctly handles GET requests. When it comes to POST requests, the $_POST
array is empty, even when things are getting POSTed.
I检查了HTTP标头被送入 php-cgi
二进制文件,它们确实包含了POST数据和 Content-type:application / x -www-form-urlencoded
标题。
I've checked the HTTP headers being fed into the php-cgi
binary and they do indeed include the POST data and the Content-type: application/x-www-form-urlencoded
header.
什么可以保持 php-cgi
二进制,看到请求中包含POST数据?
What could be keeping the php-cgi
binary from seeing that there's POST data included in the request?
我正在取得进展,我挖出来了来自 PHP源代码的一些内容:
I'm making progress, I've dug up some stuff from the PHP source code:
468:static int sapi_cgi_read_post(char * buffer,uint count_bytes TSRMLS_DC)
(我没有dea从哪里调用此函数。)
(I have no idea where this function is invoked from.)
阅读下面的答案后,我尝试了:
After reading the answer below, I tried:
<?php
var_dump($HTTP_RAW_POST_DATA);
?>
...产生了输出:
NULL
...表示更奇怪的是在这里工作。
...indicating that something even stranger is at work here.
我越来越近了......我在 / main / php_content_types.c :
I'm getting closer... I found this function in /main/php_content_types.c:
SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
......似乎是处理POST请求的代码。
...and it seems to be the code that processes POST requests.
推荐答案
我终于想出来了:
显然需要设置 CONTENT_LENGTH
环境变量。
Apparently the CONTENT_LENGTH
environment variable needs to be set.
添加:
CONTENT_LENGTH=6
export CONTENT_LENGTH
上面我的例子使它正常工作!
to my example above causes it to work properly!
这篇关于如何将POST数据传递给PHP-CGI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!