title: PHP cURL connection refused on localhost
body: <p>I'm trying to execute a cURL request in PHP to my localhost, but I get the following error:</p>
  
  <blockquote>
    <p>cURL error (7): Failed to connect to localhost port 8000: Connection refused</p>
  </blockquote>
  
  <p>I've tried to Google this message, and also found similar questions on StackOverflow, but nothing seems to be working.</p>
  
  <p><strong>curl.php:</strong></p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "localhost:8000/test.php");
  curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  $response = curl_exec($ch);
  
  if (curl_errno($ch)) {
      echo 'cURL error (' . curl_errno($ch) . '): ' . curl_error($ch);
  } else {
      echo $response;
  }
  
  curl_close($ch);
  </code></pre>
  
  <p><strong>test.php:</strong></p>
  
  <pre><code>echo json_encode(array(
      "message" =&gt; "Hello World!"
  ));
  </code></pre>
  
  <p>If I remove the "<strong>CURLOPT_IPRESOLVE</strong>" value, the request never resolves. I've also tried setting both "<strong>CURLOPT_SSL_VERIFYPEER</strong>" and "<strong>CURLOPT_SSL_VERIFYHOST</strong>" to false. Still not working.</p>
  
  <p>But if I navigate to localhost:8000/test.php in my browser, I get the correct response. I can also use the "<strong>curl localhost:8000/test.php</strong>" command and receive the correct response</p>
  
  <p>Thanks for the help!</p>