我已经在互联网上搜索了很多这个问题,即使在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共享主机上运行。任何人都可以告诉我确切的问题或我在这里做错了什么。
答案 0 :(得分:0)
添加&#39; CURLOPT_VERBOSE =&gt;真正的&#39;在你的选项数组中给出一个更详细的输出,这应该给你原因。
如果您有权访问防火墙设置,请确保连接端口实际处于打开状态。