[英]curl_exec is not working
I have this piece of code: 我有这段代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $page_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$header[] = "Accept: text/html, text/*";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$html = curl_exec($ch) or die('111');
curl_close($ch);
echo $html;
exit('1');
I have windows with latest version of Xampp installed with curl enabled. 我的Windows安装了最新版本的Xampp并启用了curl。
When I run the code it returns 111
without any errors. 当我运行代码时,它返回
111
没有任何错误。 I was expecting it to return the page content and 1
我期待它返回页面内容和
1
Don't die with a fixed error message. 不要死于固定的错误消息。 Try
尝试
$result = curl_exec($ch);
if ($result === FALSE) {
die(curl_error($ch));
}
instead. 代替。 have curl tell you WHY it failed, instead of just spitting out some pointless
111
text. 卷曲告诉你为什么它失败了,而不只是吐出一些毫无意义的
111
文本。
Try something like the example from the manual: 尝试类似手册中的示例:
if(($html = curl_exec($ch)) === false)
{
echo 'Curl error: ' . curl_error($ch);
die('111');
}
curl_close($ch);
echo $html;
exit('1');
http://php.net/manual/en/function.curl-error.php http://php.net/manual/en/function.curl-error.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.