无法使用POST方法将变量传递给CGI

时间:2017-04-05 03:27:19

标签: php http-post cgi

为了测试,我做了这个.sh:

#!/bin/bash
export GATEWAY_INTERFACE=CGI/1.1
export REQUEST_METHOD=POST 
export SCRIPT_FILENAME=/www2/post_example.php 
export CONTENT_LENGTH=12
export REDIRECT_STATUS=true
export username=bob
exec echo 'username=bob' | /usr/bin/php-cgi7.0 -e

我用来测试的php如下:

<?php
     echo $_POST['username'];
?>

每当我尝试运行脚本时,它会说:

PHP Notice:  Undefined index: username in /www2/post_example.php on line 2
Content-type: text/html; charset=UTF-8

<br />
<b>Notice</b>:  Undefined index: username in <b>/www2/post_example.php</b> on line <b>2</b><br />

我不知道我错过了什么......

1 个答案:

答案 0 :(得分:0)

I figured out that I missed the Content-Type header.

CONTENT_TYPE=application/x-www-form-urlencoded