I'm trying to send a JSON object to a PHP script with Powershell, and have that PHP script simply return what it gets as JSON...
In Powershell I'm doing this:
$a = New-Object System.Collections.ArrayList;
$a.Add(@{
'prop1' = 'something'
'prop2' = 'something else'
});
$a.Add(@{
'prop1' = 'green'
'prop2' = 'blue'
});
$b = New-Object System.Collections.ArrayList;
$b.Add(@{
'prop1' = 'another'
'prop2' = 'yet another'
});
$b.Add(@{
'prop1' = 'red'
'prop2' = 'black'
});
$json = @{
'first' = $a
'second' = $b
} | ConvertTo-Json;
$json
At which point $json is a String like this:
{
"second": [
{
"prop2": "yet another",
"prop1": "another"
},
{
"prop2": "black",
"prop1": "red"
}
],
"first": [
{
"prop2": "something else",
"prop1": "something"
},
{
"prop2": "blue",
"prop1": "green"
}
]
}
Then I POST a Invoke-WebRequest with $json as the body:
(Invoke-WebRequest -Uri $url -ContentType 'application/json' -Method Post -Body $json).Content;
The target is this PHP5 script:
<?php
header('Content-Type:application/json');
echo json_encode(array("POST" => $_POST, "GET" => $_GET));
?>
But the response is just empty:
{"POST":[],"GET":[]}
I've tried getting PHP to just echo back a static string, which works fine, but can you see anything wrong with how I'm POSTing/accepting/responding here? I'm stumped