Question

my Perl script is performing the following POST request.

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))
            ]
        ]
    );

The request is directed to a PHP script which is written like this:

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

Currently I am not able to get the payload out of the POST Request - not even a single bit - also using gzencode() to encode the input throws 'data error'.

What am I doing wrong?

Was it helpful?

Solution

Just use the $_POST variable.

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

no need for file_get_contents("php://input")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top