我使用php curl从同一域url中的php脚本获取内容.但我得到curl_exec错误.卷曲错误代码为28或操作超时.经过几天的调试,我发现它可以在非脚本页面上运行,如htm,但不是php,如果url是不同域上的脚本,它也可以工作.我已经调试了几天,没有找到解决方案.帮助赞赏.
$url = 'http://...';
$agent = '';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8);
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
$result = curl_exec ($ch);
print "<pre>\n";
print_r(curl_getinfo($ch));
// get error info echo "\n\ncURL error number:" .curl_errno($ch);
// print error info echo "\n\ncURL error:" . curl_error($ch);
print "</pre>\n";
curl_close ($ch);
echo $result;
Run Code Online (Sandbox Code Playgroud)
cURL错误号:28 cURL错误:
操作在8000毫秒后超时,接收到0个字节
好的:
失败:$url = http://.../page.htm$url = http://.../page.php