【发布时间】:2015-03-15 15:39:45
【问题描述】:
即使在 stackoverflow 上,我也在互联网上搜索了很多有关此问题的内容,但无法找到某些解决方案。我正在使用以下代码向 https 网站之一发出 curl 请求。
<?php
/**
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
* array containing the HTTP server response header fields and content.
*/
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks
CURLOPT_SSL_VERIFYHOST => false
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
echo '<pre>';
print_r(get_web_page('https://savedeo.com/download?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbVl3om0-GFE'));die;
?>
此代码在我的 localhost xampp 上运行良好,但在 hostgator 共享主机上运行不正常。谁能告诉我确切的问题或我在这里做错了什么。
【问题讨论】:
-
echo phpinfo();并确保curl已安装并在共享主机上运行 -
是的,它为 http 网站启用并正常工作
-
请发布您的
curl error