title: How to POST JSON from Powershell to a PHP script
body: <p>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...</p>
  
  <p>In Powershell I'm doing this:</p>
  
  <pre><code>$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
  </code></pre>
  
  <p>At which point <code>$json</code> is a String like this:</p>
  
  <pre><code>{
      "second":  [
                     {
                         "prop2":  "yet another",
                         "prop1":  "another"
                     },
                     {
                         "prop2":  "black",
                         "prop1":  "red"
                     }
                 ],
      "first":  [
                    {
                        "prop2":  "something else",
                        "prop1":  "something"
                    },
                    {
                        "prop2":  "blue",
                        "prop1":  "green"
                    }
                ]
  }
  </code></pre>
  
  <p>Then I POST a <code>Invoke-WebRequest</code> with <code>$json</code> as the body:</p>
  
  <pre><code>(Invoke-WebRequest -Uri $url -ContentType 'application/json' -Method Post -Body $json).Content;
  </code></pre>
  
  <p>The target is this PHP5 script:</p>
  
  <pre><code>&lt;?php
  header('Content-Type:application/json');
  echo json_encode(array("POST" =&gt; $_POST, "GET" =&gt; $_GET));
  ?&gt;
  </code></pre>
  
  <p>But the response is just empty:</p>
  
  <pre><code>{"POST":[],"GET":[]}
  </code></pre>
  
  <p>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</p>