cURL和Apache可能存在的问题

时间:2013-02-28 12:11:43

标签: php apache curl

我使用cURL从外部域导入了一些数据,直到我尝试使用此URI:http://www.airbnb.com/calendar/ical/760186.ics?s=29623a93eb0e693c77591a711f082f06,这是一个日历。 我可以在命令行上成功运行它(尝试自己): 壳>>卷曲https://www.airbnb.com/calendar/ical/760660.ics?s=593cc556438a8f0919beb6107b6f508d,所以它不是网络问题。

但我的php脚本(确实返回其他URI)不要返回此内容。或者更好,它会返回错误。

这里是小php

function file_get_contents_curl($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$ical1= "http://www.airbnb.com/calendar/ical/760186.ics?s=29623a93eb0e693c77591a711f082f06";
echo file_get_contents_curl($ical1);

我认为这与我的apache或php配置有关,因为它在appfog上运行,并且运行我的旧xampp安装。 要恢复:所有URI都使用旧的xampp instalation,现在只是示例中的那个失败了。

在我的phpinfo()上我可以读到:

cURL support enabled
cURL Information 7.24.0
Age 3
Features
AsynchDNS Yes
Debug No
GSS-Negotiate Yes
IDN No
IPv6 Yes
Largefile Yes
NTLM Yes
SPNEGO No
SSL Yes
SSPI Yes
krb4 No
libz Yes
CharConv No
Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Host i386-pc-win32
SSL Version OpenSSL/1.0.1c
ZLib Version 1.2.5
libSSH Version libssh2/1.3.0

1 个答案:

答案 0 :(得分:0)

试试这个:

function get_remoteDATA($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    //If POST METHOD IS NEEDED
    //curl_setopt($ch, CURLOPT_POST, TRUE);
    //curl_setopt($ch, CURLOPT_POSTFIELDS, "var1=1&var2=2&var3=3");
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
        //curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 9);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$cntn= get_remoteDATA('http://www.airbnb.com/calendar/ical/760186.ics?s=29623a93eb0e693c77591a711f082f06');
print_r($cntn);