[PHP] No payload in HTTP integration endpoint POST

Hello everyone,

first of all, very nice project guys. Congratulations.
Secondly: I’m trying to use HTTP integration towards a simple Apache PHP local server, for testing purposes.
My problem is that my endpoint gets called correctly but recieves no POST data. PHP tells $_POST is an empty array. I was expecting the payload in POST, shouldn’t I? Endpoint gets called, as Lora App Server console confirms:

e[36mINFOe[0m[7554] handler/mqtt: publishing message e[36mqose[0m=0 e[36mtopice[0m=application/1/device/0001020304050607/rx
e[36mINFOe[0m[7554] handler/http: publishing data-up payload e[36mdev_euie[0m=0001020304050607 e[36murle[0m=“http://localhost/loraintegration/index.php?mode=uplink

I can see the packet reaching the WebUI Live Monitor proudly showing the ambitious (base64ed) “HELLO WORLD!!!”.

What reason could prevent my endpoint from getting POST payload data?
By the way, tried MQTT subscription and payload is present there.

Thanks

How do you monitor the POST payload? I mean how do you know that POST is an empty array ? Do you log it or persist it ?

I’m just inspecting POST input with a trivial PHP script like:

$pathname = __DIR__."/dumps/test.log";
file_put_contents($pathname, var_export($_POST, true));

whose output is:

array (
)

where I expected some input from POST (the payload).

I don’t have any PHP experience so I can’t review if your code is correct. Could you test with for example Postbin: http://postb.in/? If you see the payload there, then at least you have isolated the issue to your PHP code.

I bet that the HTTP request is content type “application/json” and not “application/x-www-form-urlencoded”, try something like this:

$data = file_get_contents('php://input');
file_put_contents($pathname, $data);
2 Likes

Great @stelios, you just hit the point. Jackpot!
My error was to expect PHP to automatically parse $_POST data from JSON string. Parsing raw data from input did the trick.
By the way “Content-Type” was “application/json” indeed.

$pathname = __DIR__."/dumps/test.log";
$json = json_decode(file_get_contents("php://input"), true);
file_put_contents($pathname, var_export($json, true));

Thank you both for your time.

1 Like