cURL表现很奇怪 [英] cURL acting very strange

查看:101
本文介绍了cURL表现很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在成功使用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 ,所以这不是网络问题.

I'm importing some data from external domains successful with cURL, until I tried with this URI: http://www.airbnb.com/calendar/ical/760186.ics?s=29623a93eb0e693c77591a711f082f06, which is a ics calendar. I can successfully run it on a command line (try for your selves): shell>> curl https://www.airbnb.com/calendar/ical/760660.ics?s=593cc556438a8f0919beb6107b6f508d, so it's not a network issue.

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

but my php script (that do return other URI) DO NOT return this. or better it return 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安装,现在只有示例中的URI失败了.

I do think this has something to do with my apache or php configuration, because it runs on appfog and it run with my old xampp instalation. To resume: all URI worked with old xampp instalation and now just the one from the example fails.

在我的phpinfo()上,我可以阅读:

on my phpinfo() i can read:

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

推荐答案

URL是有效的,仅将URL放入浏览器就可以毫无问题地下载.

The URL is valid and can be downloaded no problems just by putting the URL in to a browser, so that isn't your problem.

URL重定向到相同的URL,但在安全的服务器上,但是您已经设置了CURLOPT_FOLLOWLOCATION,所以这也不是问题.

The URL redirects to the same URL but on a secure server, but you have set CURLOPT_FOLLOWLOCATION so that isn't your problem either.

但是,安全网址会执行javascript重定向到英国站点,这是您的问题.您正在拉回错误的文件.

However, the secure URL carries out a javascript redirect to the UK site, and this is your problem. You're pulling back the wrong file.

尝试使用URL https://www.airbnb.co.uk/calendar/ical/760186.ics?s=29623a93eb0e693c77591a711f082f06进行尝试,并查看其运行方式.

Try it with the URL https://www.airbnb.co.uk/calendar/ical/760186.ics?s=29623a93eb0e693c77591a711f082f06 instead and see how it goes.

这篇关于cURL表现很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆