Php 是否包括必要的卷曲头?
我正在制作一个应用程序来使用Youtube数据API。我认为CURL永远是比PHP的Php 是否包括必要的卷曲头?,php,curl,youtube,youtube-api,youtube-data-api,Php,Curl,Youtube,Youtube Api,Youtube Data Api,我正在制作一个应用程序来使用Youtube数据API。我认为CURL永远是比PHP的file\u get\u contents()更好的选择。对于CURL,我需要知道为了获得优化的性能,请求中应该包括哪些头文件 我需要设置一些超时设置、错误处理方法等 Thanx提前。您可以尝试以下方法: $ch = curl_init('your url'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); cur
file\u get\u contents()
更好的选择。对于CURL,我需要知道为了获得优化的性能,请求中应该包括哪些头文件
我需要设置一些超时设置、错误处理方法等
Thanx提前。您可以尝试以下方法:
$ch = curl_init('your url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive',
'Pragma: no-cache',
'Cache-Control: no-cache'
));
$result = curl_exec($ch);
if($result == FALSE) {
var_dump(curl_error($ch)); //handling error
} else { //success
echo $result;
}
你可以试试这样的东西:
$ch = curl_init('your url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
'User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive',
'Pragma: no-cache',
'Cache-Control: no-cache'
));
$result = curl_exec($ch);
if($result == FALSE) {
var_dump(curl_error($ch)); //handling error
} else { //success
echo $result;
}
您可以对文件\u get\u contents()使用http包装器:
您可以对文件\u get\u contents()使用http包装器:
你能提出请求/回复样本吗?GET&mine=True你能提出请求/回复样本吗?GET&mine=True那么你建议我把文件内容改为curl吗?由你决定。无论如何都将使用CURL扩展名。那么你是不是建议我使用file\u get\u contents而不是CURL?这取决于你。无论如何,将使用卷曲扩展。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_URL, $IP);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('User-Agent: 1.11.4 Red Hat modified',"Host : $host",'Connection: Keep-Alive'));//it might need
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);//just get the header info only
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);//set your time out
$data = curl_exec($ch);
return $data;