Doflaminhgo
Doflaminhgo

Reputation: 577

Empty $_POST while sending data in POST-request with curl (command line) to php-script

I am currently trying to send a POST-request to a PHP-script on a VPS. The request is made with curl and looks like this:

curl -L -X POST --cacert /home/user/server.pem --data "analysis_results=1" http://server-ip-here/api/v2/update_analysis_results.php

The PHP-Script only contains the following:

<?php

echo "Helloooo World!";

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    print_r($_POST);
    if ( !empty($_POST) ) {
            echo "post";
    }
}
?>

After executing the curl command the following is returned:

Helloooo World!Array
(
)

I can't figure out why the $_POST-Array is empty. Any ideas?

Edit: replaced, "echo $_POST" with "print_r($_POST)"

Upvotes: 0

Views: 197

Answers (1)

db1975
db1975

Reputation: 775

you should use print_r($_POST) instead of echo $_POST;

$_POST is an array.

echo $_POST['analysis_results'];

Upvotes: 0

Related Questions