【问题标题】:problems with cURL and probably ApachecURL 和 Apache 的问题
【发布时间】:2013-02-14 15:03:18
【问题描述】:

我正在使用 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

【问题讨论】:

  • 刚刚尝试了我的 mamp 设置,您的脚本运行良好(第一个 url 重定向到输出日历数据的第二个)。当你得到 $data==null 时尝试阅读 curl_error()
  • curl_error 给出一个空字符串,按手册说没有发生错误。谢谢我还没试过。 (返回提交消息很痛苦......)这个问题发生在windows服务器上,我放弃并转向linux。

标签: php apache curl


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 2012-06-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多