title: PHP curl: CURLOPT_URL, CURLOPT_POST, and CURLOPT_POSTFIELDS
body: <p>If I have a URL that looks like this:</p>
  
  <pre><code>$url = 'http://domain.com/?foo=bar';
  </code></pre>
  
  <p>And then execute curl as follows:</p>
  
  <pre><code>$resource = curl_init();
  curl_setopt($resource, CURLOPT_URL, $url);
  curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
  $result = curl_exec($resource);
  curl_close($resource);
  </code></pre>
  
  <p>I understand that I make this request via GET (default).</p>
  
  <p>Now if I set the following option in the same scenario:</p>
  
  <pre><code>curl_setopt($resource, CURLOPT_POST, 1);
  </code></pre>
  
  <p>I understand it uses POST instead of GET, but does it then POST <code>foo</code> with a value of <code>bar</code>? Or would the proper way for that be:</p>
  
  <pre><code>$url = 'http://domain.com/';
  $post = 'foo=bar';
  $resource = curl_init();
  curl_setopt($resource, CURLOPT_URL, $url);
  curl_setopt($resource, CURLOPT_POST, 1);
  curl_setopt($resource, CURLOPT_POSTFIELDS, $post);
  curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
  $result = curl_exec($resource);
  curl_close($resource);
  </code></pre>
  
  <p>And what happens if I do this (i.e. submit the value in the URL and via CURLOPT_POSTFIELDS):</p>
  
  <pre><code>$url = 'http://domain.com/?foo=bar';
  $post = 'foo=bar';
  $resource = curl_init();
  curl_setopt($resource, CURLOPT_URL, $url);
  curl_setopt($resource, CURLOPT_POST, 1);
  curl_setopt($resource, CURLOPT_POSTFIELDS, $post);
  curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
  $result = curl_exec($resource);
  curl_close($resource);
  </code></pre>
  
  <p>How will the data be submitted in that scenario?</p>