title: Fetch JSON response from API using php
body: <p>I'm trying to fetch data from API, but no data returns.
  I try the API request in postman and it's working but in my php code nothing gets returned.</p>
  <pre><code>$uri = 'https://example.com';
  
  $opts = array(
    'http' =&gt; array(
      'method'=&gt;'POST', 
      'header'=&gt;'Content-Type: application/x-www-form-urlencoded', 
    )
  );
  
  $context = stream_context_create($opts);
  
  $result = file_get_contents($uri, false, $context);
  
  print $result;
  </code></pre>
  <p>or using curl</p>
  <pre><code>$curl = curl_init();
  
  curl_setopt_array($curl, array(
    CURLOPT_URL =&gt; 'https://example.com',
    CURLOPT_RETURNTRANSFER =&gt; true,
    CURLOPT_ENCODING =&gt; '',
    CURLOPT_MAXREDIRS =&gt; 10,
    CURLOPT_TIMEOUT =&gt; 0,
    CURLOPT_FOLLOWLOCATION =&gt; true,
    CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST =&gt; 'POST',
  ));
  
  $response = curl_exec($curl);
  
  curl_close($curl);
  echo $response;
  </code></pre>
  <p>the error is</p>
  <pre><code>file_get_contents(https://example.com): failed to open stream: HTTP request failed! HTTP/1.1 411 Length Required
  </code></pre>
  <p>Note: the response size in postman is 9.83, is this maybe an issue?</p>