title: POST request with php
body: <p>I've been trying to figure out how to make a post request against this kind of json without any luck</p>
  
  <pre><code>URL:/v1.0/country/{countryId}/city/search
  Method:POST
  Content-Type: application/json
  Body: {\"city\":[{\"cityId\":1234, \"min\":0, \"max\":15}]}
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Edit:
  Here is the code Im working with</p>
  
  <pre><code>&lt;?php
  
  // Auth
  $auth = base64_encode("userauthurl:password");
  $authContext = stream_context_create(['http' =&gt; ['header' =&gt; "Authorization: Basic $auth"]]);
  $tokenUrl = 'https://tokenurl.com/token';
  $tokenResponse = file_get_contents($tokenUrl, false, $authContext );
  $tokenObj = json_decode($tokenResponse);
  $access_token = $tokenObj-&gt;access_token;
  
  // POST params
  $postData = array(
    'body' =&gt; '{\"city\":[{\"cityId\":1234, \"min\":0, \"max\":5}]}'
  );
  
  // Context POST
  $contextGet = stream_context_create([
      "http" =&gt; 
      ["method" =&gt; "POST", 
      "header" =&gt; "Accept: application/json\r\n". 
      "Authorization: Bearer $access_token\r\n",
      "content" =&gt; json_encode($postData)
      ]]);
  
  
  $cityUrl = 'https://urltosendto.com/v1.0/country/{countryId}/city/search';
  $cityResponse = file_get_contents($cityUrl, false, $contextGet);
  $city = json_decode($cityResponse);
  echo json_encode($cityResponse);
  
  
  ?&gt;
  </code></pre>