PHP卷曲工作的somecase,而不是在一些情况下
问题描述:
本规范运作良好PHP卷曲工作的somecase,而不是在一些情况下
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://ipdev.in/");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
echo $output;
// close curl resource to free up system resources
curl_close($ch);
?>
但空两个一堆代码不工作。我没有得到一个错误,但在这些情况下,浏览器加载栏只是旋转和旋转,永不停止。该页面显示了很长一段时间的加载和加载,但没有从URL加载。哪里有问题 ?
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "https://iiitd.ac.in/");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
echo $output;
// close curl resource to free up system resources
curl_close($ch);
?>
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://iiitd.ac.in");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = curl_exec($ch);
echo $output;
// close curl resource to free up system resources
curl_close($ch);
?>
答
链接https://iiitd.ac.in/
被重定向到https://www.iiitd.ac.in/
所以你需要修改你的卷曲的代码。您需要将CURLOPT_FOLLOWLOCATION
设置为true
。
有以下解决方案来看看:
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "https://iiitd.ac.in/");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// added follow location
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// $output contains the output string
$output = curl_exec($ch);
echo $output;
// close curl resource to free up system resources
curl_close($ch);
我的问题是;为什么你在第二个例子中两次运行卷曲? – Darren