Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How can I make curl to work in my local environment?

Hi, I am doing a simple GET request using curl but I can't make it work. I have curl installed and I was able to do some POST/GET requests to other sites so I know it's working.

class TestsController extends ControllerBase{
    public function curlAction{
        $this->view->disable();
        $this->response->setStatusCode(200,'OK');
        $this->response->setJsonContent(['content' => 'success']);
        $this->response->send();
    }

    public function sendAction(){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://localhost/tests/curl");
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        $output = curl_exec($ch);
        curl_close($ch);
        var_dump($output); //result is always false
    }

}

The curl action works when I am using cli CURL and when using POSTMAN, but no luck when trying the send action. Am I missing something?

--EDIT--

When I try to output curl error it says couldn't connect to host.



289
Accepted
answer

I got it working. Seems like my installation of curl used a different port. I configured it to the default and it worked.