简体   繁体   中英

Commandline php curl not working?

Hello i have php for commandline and trying to execute a curl link, but it don't works!

<?php 
$ch = curl_init("https://albinstuff.net"); 
$result = curl_exec($ch);

echo $result;
?>

It outputs nothing, not even an error ...

I have enabled php_curl.dll extension ...

Try this :

$url = 'http://yourUrl.com';
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_POST, 1);
//    curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml_data); // use this for post fields
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); 
$data = curl_exec ($ch);
curl_close ($ch);

curl by default OUTPUTS whatever it finds, unless you turn on the "return transfer" option. As well, if curl fails, curl_exec will return a boolean false, which will print as an empty string.

Try:

$ch = curl_init(...);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if($result === false) {
    echo "Curl failed with error: ", curl_error($ch);
}
echo $result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM