title: application/x-www-form-urlencoded content type hacks curl response in php
body: <p>It seems that <strong>Content-Type: application/x-www-form-urlencoded</strong> just hacked my curl result</p>
  
  <p>I have a curl request below</p>
  
  <pre><code>curl -k -X POST \
    --header "Content-Type: application/x-www-form-urlencoded" \
    --header "Accept: application/json" \
    --data-urlencode "grant_type=naco:pdata:params" \
    --data-urlencode "apikey=&lt;apikey&gt;" \
    "https://api_endpoint"
  </code></pre>
  
  <p>Here is how I successful post data and get response as expected.
  Here is the succesful result</p>
  
  <pre><code>{
    "product_id": "101",
    "product_name": "Television"
  
  }
  </code></pre>
  
  <p>Now when I echoed or var_dump the result <strong>($res)</strong> as per code below then <strong>$res</strong> is empty and as such,
  <strong>product_name</strong> and <strong>product_id</strong> cannot be printed and yet am having my result response on the page displayed.</p>
  
  <p>I now discovered that it was the <code>Content-Type: application/x-www-form-urlencoded</code> that forces the result to be displayed via
  header but cannot allow <strong>$res</strong> response to echo the result.</p>
  
  <p>Please how do Print <strong>product_id</strong> and <strong>product_name</strong></p>
  
  <pre><code>$header= array(                                                                          
   'Content-Type: application/x-www-form-urlencoded',                                                                               
      "Accept: application/json");                                                                       
  
  $builder= http_build_query([
     'grant_type'=&gt;"naco:pdata:params", 
      'apikey'=&gt;"xxxxxxx"]);
  
  
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "https://api_endpoint");
  curl_setopt($ch, CURLOPT_POSTFIELDS, $builder);
  
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);  
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');
  
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
  
   $res = curl_exec($ch);
  
  curl_close($ch);
  </code></pre>
  
  <p><strong>//code below shows empty result and yet i can still see the result response on the page</strong></p>
  
  <pre><code>echo $res
  var_dump($res);
  $json = json_decode($res, true);
  echo $product_name = $json['product_name'];
  echo $product_id = $json['product_id'];
  </code></pre>