Post request is received on machine but server does not recognize it when the source is not local

Viewed 56

I have setup an Apache webserver on my computer using the tool XAMPP. It is running a PHP script that checks for POST requests and stores POST values to a txt file.

<html>
<body>
<?php
$filename = "temperatures.txt";
$current_content = file_get_contents($filename);
if (!empty($_POST))
{
    $temperature = $_POST["temperature"];
    $new_contents = $current_content . $temperature . "\n";
    file_put_contents($filename, $new_contents);
}
else
{
    $new_contents = $current_content . "unknown\n";
    file_put_contents($filename, $new_contents); 
}
?>
</body>
</html>

I tested the script by generating a POST request using Curl, a command line tool. I did this from the local machine on which the server is running. This is the command that I ran:

curl -i -X POST -H 'Content-Type: application/json' -d "temperature=10" http://192.168.88.254/index.php"

Then I also have an IoT gateway/router within the same LAN network, which also sends HTTP POST requests. Using Wireshark I verified that packets from both sources are received by the machine.

The first entry is from the IoT gateway, the second one from curl.

  1. enter image description here

  2. enter image description here

However, the script outputs the 'unknown' value to the file when the IoT gateway was the source.

Does anyone have any idea why Wireshark catches the post value from the IoT gateway, but the server does not?

temperatures.txt
10
unknown

Results in apache log

192.168.88.254 - - [12/Mar/2021:11:40:06 +0100] "POST /index.php HTTP/1.1" 200 29 "-" "curl/7.55.1"
192.168.88.1 - - [12/Mar/2021:11:40:25 +0100] "POST /index.php HTTP/1.1" 200 29 "-" "Mikrotik/6.x Fetch"
0 Answers
Related