I have tried examples from all over the globe and all have the same result. I know it must be something simple that I am missing. I am running in a Windows 11 cmd, no errors are returned and it does call the PHP script but can’t get the JSON in the PHP script. I tried http and https as well.
cURL Version:
curl 8.4.0 (Windows) libcurl/8.4.0 Schannel WinIDN
Release-Date: 2023-10-11
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS HSTS HTTPS-proxy IDN IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI threadsafe Unicode UnixSockets
Here is the command:
curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe","age":30,"city":"New York"}' http://myserver/hello.php
Below is the PHP script, excuse the lines that are commented out for they reflect different things I have tried. Note I want to pass JSON not http://myserver/hello.php?name=John Doe&...
hello.php
<?php
//header('content-type: application/json');
//$json = file_get_contents('php://input');
//$data = var_dump(json_decode($json, true));
//$data = var_dump(json_decode($_GET, true));
$data = json_decode(file_get_contents('php://input'), true);
//$data = json_decode($_POST);
//$data = $_POST;
//$dump = print_r($data);
//$dump = print_r($data);
//$arrayJSON = json_decode($str_json);
//$data = json_decode($_POST);
file_put_contents('test.txt', $data['name']);
?>