title: CURLOPT_POST vs. CURLOPT_POSTFIELDS: Is CURLOPT_POST option required?
body: <p>I'm new to <strong>cURL</strong> in PHP. I have a question regarding usage of curl options.</p>
  
  <p>Consider two script files: test1.php and test2.php both present in root www. I'm using <strong>Ubuntu 12.04 LTS</strong>. The libcurl version for PHP is <strong>7.22.0</strong>.</p>
  
  <p><strong>Contents of test1.php</strong></p>
  
  <pre><code>&lt;?php
      $ch = curl_init();
      $post_data = array(
          'firstname' =&gt; 'John',
          'lastname' =&gt; 'Doe'
      );
      curl_setopt($ch, CURLOPT_URL, 'localhost/test2.php');
      curl_setopt($ch, CURLOPT_POST, TRUE);   //is it optional?
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
      curl_exec($ch);
      curl_close($ch);
  ?&gt;
  </code></pre>
  
  <p><strong>Contents of test2.php</strong></p>
  
  <pre><code>&lt;?php 
      var_dump($_POST);
  ?&gt;
  </code></pre>
  
  <p>When I execute test1.php via browser, I can see results posted. Now if I remove curl option containing <strong>CURLOPT_POST</strong>, the example still works. Even if I set <strong>CURLOPT_POST</strong> to false, post is performed and result is displayed. So, is that <strong>CURLOPT_POST</strong> not required at all? It looks option <code>CURLOPT_POSTFIELDS</code> takes care of sending data via <strong>POST</strong> without use of <code>CURLOPT_POST</code> option. When I print <code>$_SERVER</code> in test2.php, request method is always set to <code>POST</code> (with or without option <code>CURLOPT_POST</code>).</p>
  
  <p>Could anyone please let me know the exact use of <code>CURLOPT_POST</code> option? Is it neccessary required for sending data via <code>POST</code>?</p>