0

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

但我的 php 脚本(确实返回其他 URI)不返回这个。或者更好的是它返回false。

这是小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 安装,现在只有示例中的一个失败。

在我的 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
4

1 回答 1

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);
于 2014-02-12T13:59:09.040 回答