使用PHP从Post Request获取有效负载

时间:2014-03-17 17:24:11

标签: php perl rest post gzip

我的Perl脚本正在执行以下POST请求。

my $req = $ua->post(
        $post_target,
        Content_Type => 'form-data',
        Content => [
            'data' => [
                undef,
                'json.gz',
                'Content-Type'     => 'application/json',
                'Content-Encoding' => 'gzip',
                'Content'          => Compress::Zlib::memGzip(encode_json($payload))
            ]
        ]
    );

请求被定向到一个PHP脚本,其编写如下:

$input = file_get_contents("php://input");
$filename = 'test';
$filehandle = fopen($filename, 'w');
fwrite($filehandle, $input);
fclose($filehandle);

目前我无法从POST请求中获取有效负载 - 甚至一点也不能 - 也使用gzencode()来编码输入抛出'数据错误'。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

只需使用$_POST变量即可。

echo "<pre>";    // makes print_r pretty
print_r($_POST); // dumps all of the POST data
echo "</pre>";   
echo $_POST['Content-Type']; //etc ... 

不需要file_get_contents("php://input")

相关问题