Commandline php curl无法正常工作?

时间:2014-06-13 18:05:56

标签: php curl cmd

你好我有命令行的php和尝试执行卷曲链接,但它不起作用!

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

echo $result;
?>

它什么都不输出,甚至没有输出......

我已启用php_curl.dll扩展程序...

2 个答案:

答案 0 :(得分:1)

试试这个:

$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);

答案 1 :(得分:0)

curl默认情况下OUTPUTS无论发现什么,除非你打开&#34;返回转移&#34;选项。同样,如果curl失败,curl_exec将返回一个布尔值false,它将打印为空字符串。

尝试:

$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;