HTTP_CODE 0 are returned curl API v1

July 9, 2014 5.8k views

hello digital ocean community.. I'm new to digital ocean and I am having trouble with the V1 API.. I have created a web service where users are capable of creating a server/droplet with just a click away.. here is the function for creating the server

private function v1apiGET($url,$data) {
        $ch = curl_init();

        $data['client_id'] = $this->clientKey;
        $data['api_key'] = $this->apiKey; 

        $query = http_build_query($data, '', '&');

        curl_setopt($ch,CURLOPT_URL, $this->apiUrl.$url.$query);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, '3');
        $response = curl_exec($ch);

        $responseHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if($responseHttpCode == 403) {
            throw new CHttpException(403,'Your app key is not valid');
        } elseif($responseHttpCode == 200) {
            // nop
        } else {
            die($this->apiUrl.$url.$query);//throw new CHttpException('Uknown Error: ' . $responseHttpCode );

        //close connection

        return CJSON::decode($response);

however I always get an "HTTP_CODE: 0." as you can see in the last part of my $responseHttpCode if statement I have displayed the url. I have tested this url by directly inputting in url bar and it worked, but curl php script don't work can anybody inform me of any mistakes from my code or what am I doing wrong.. thanks ..

1 comment
  • HTTP_CODE 0 means that cURL couldn't connect to the server. What's the value of



Be the first one to answer this question.