Jump to content

CURL working from localhost but not on live site


pranvkavi

Recommended Posts

I have a CURL code that fetches some XML content from a remote server. I get the expected output on my localhost (XAMPP on windows). But from the live site(hosted on Linux), I get the CURL error:'couldn't connect to host'.

 

	function DownloadUrl($Url, $p){

	// is curl installed?
	if (!function_exists('curl_init')){ 
		die('CURL is not installed!');
	}

       // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, CURLOPT_URL, $Url);

   curl_setopt ($ch, CURLOPT_POSTFIELDS, $p);
   curl_setopt ($ch, CURLOPT_POST, 1);
        //return the transfer as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // $output contains the output string
        $output = curl_exec($ch);
        
   if($output === false)
	   echo 'Curl error: ' . curl_error($ch);
   else
    		print $output;
        // close curl resource to free up system resources
        curl_close($ch);          
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.