I'm trying to execute a cURL request in PHP to my localhost, but I get the following error:
cURL error (7): Failed to connect to localhost port 8000: Connection refused
I've tried to Google this message, and also found similar questions on StackOverflow, but nothing seems to be working.
curl.php:
$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);
test.php:
echo json_encode(array(
"message" => "Hello World!"
));
If I remove the "CURLOPT_IPRESOLVE" value, the request never resolves. I've also tried setting both "CURLOPT_SSL_VERIFYPEER" and "CURLOPT_SSL_VERIFYHOST" to false. Still not working.
But if I navigate to localhost:8000/test.php in my browser, I get the correct response. I can also use the "curl localhost:8000/test.php" command and receive the correct response
Thanks for the help!