title: How to hit url in using POST request in php
body: <p>How to hit a url with the Content-Type header set to application/json.</p>
  
  <p>My code returns "request not successfull" (the else side of the condition). I'm a beginner so please help me understand why this is not working.</p>
  
  <p>Code:</p>
  
  <pre><code>$data_string=json data here;    
      $ch = curl_init('www.here is url');                                                                      
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                    
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));                                                                                                                                  
      if(curl_exec($ch))
          echo "request successfull";
      else
          echo "request not successfull"
  
      curl_close($ch);
  </code></pre>