Trying to build a client/server app with Python as the client and PHP as the server.
Testing the server-side receiving now to be able to process data but I'm coming up empty.
Client:
import requests, json
def main():
## Functions to get system info working fine
machine = {
"hostname" : hostname,
"system" : system,
"cpu_count" : cpu_count,
"cpu_usage" : cpu_usage,
"memory_total" : memory_total,
"memory_used" : memory_used,
"memory_used_percent" : memory_used_percent,
"drives" : disks,
"network_up" : network_stats["traffic_out"],
"network_down" : network_stats["traffic_in"]
}
# print(machine) displays expected output
post_data(machine)
def post_data(machine):
try:
endpoint = "http://monitor.localhost.local/api/"
r = requests.post(url = endpoint, json = machine)
print("POST:",r)
print(r.content)
except requests.exceptions.RequestException as e:
print("\nPOST Error:\n",e)
main()
Server:
<?php
header('Access-Control-Allow-Origin: *');
var_dump($_POST);
?>
I'm receiving a 200 okay response but with a response that $_POST is completely empty.
I've also tried
data = json.dumps(machine)
post_data(data)
...
r = requests.post(url = endpoint, data= machine)
All to no avail. Am I missing something to be able to process the POST request on a PHP server?
EDIT: An example of the machine variable with actual data is
{
"hostname": "WORK-LAPTOP1",
"system": {
"name": "Windows",
"version": "10"
},
"cpu_count": 4,
"cpu_usage": 17.9,
"memory_total": 8440942592,
"memory_used": 6244225024,
"memory_used_percent": 74.0,
"drives": [
{
"name": "C:\\",
"mount_point": "C:\\",
"type": "NTFS",
"total_size": 536224985088,
"used_size": 167306108928,
"percent_used": 31.2
},
{
"name": "D:\\",
"mount_point": "D:\\",
"type": "NTFS",
"total_size": 463332921344,
"used_size": 49498419200,
"percent_used": 10.7
}
],
"network_up": 54,
"network_down": 4150
}