POST data are not received when a PHP script is called remotely

246 Views Asked by At

I don't receive $_POST data in a PHP script when it is called remotely. I tried it using cURL and Postman.

Content-type: form-data

curl --location --request POST 'http://example.com/backend.php?gateway=test' --form 'status=AP'

I would expect status in POST.

Response:

2020-09-22 13:19:27

JSON POST:

REQUEST:
Array
(
    [gateway] => test
)

GET:
Array
(
    [gateway] => test
)

POST:
Array
(
)

Content-Type: application/x-www-form-urlencoded'

curl --location --request POST 'http://example.com/backend.php?gateway=test' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'status=AP'

I would expect status in POST.

Response:

2020-09-22 12:59:00

JSON POST:

REQUEST:
Array
(
    [gateway] => test
)

GET:
Array
(
    [gateway] => test
)

POST:
Array
(
)

Content-Type: application/json'

curl --location --request POST 'http://example.com/backend.php?gateway=test' --header 'Content-Type: application/json' --data-raw '{ "status": "AP" }'

I would expect status in JSON POST.

Response:

2020-09-22 13:20:43

JSON POST:

REQUEST:
Array
(
    [gateway] => test
)

GET:
Array
(
    [gateway] => test
)

POST:
Array
(
)

Here is the code from backend.php

<?php
header('Access-Control-Allow-Origin: *');

$json = file_get_contents("php://input");

echo '<pre>';
echo date('Y-m-d H:i:s') . "\n";
echo "\n";
echo "JSON POST:\n";
if ($json) {
    print_r(json_decode($json, true));
}
echo "\n";
echo "REQUEST:\n";
print_r($_REQUEST);
echo "\n";
echo "GET:\n";
print_r($_GET);
echo "\n";
echo "POST:\n";
print_r($_POST);

It works expected in localhost, but not on production. PHP version on production is 5.5.38.

1

There are 1 best solutions below

0
Sumit Wadhwa On

strange. it should work the way you're trying. can you try this:

curl -d "status=AP" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://example.com/backend.php?gateway=test