我尝试转换此行命令(有效):
curl -i https://myurl >toto.txt
在脚本 php 中(不起作用):
$ch_rech = curl_init();
curl_setopt($ch_rech, CURLOPT_URL, "https://myurl");
curl_setopt($ch_rech, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch_rech);
curl_close($ch_rech);
$Results = ob_get_contents();
ob_end_clean();
我该怎么办?
谢谢
试试看:
$ch_rech = curl_init();
curl_setopt($ch_rech, CURLOPT_URL, 'https://myurl');
curl_setopt($ch_rech, CURLOPT_HEADER, false);
curl_setopt($ch_rech, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec ($ch_rech);
$httpStatus = curl_getinfo($ch_rech, CURLINFO_HTTP_CODE);
curl_close ($ch_rech);
$resp 包含输出(如果有错误则为 false) $httpStatus 包含 (显然 :-) ) 返回的 HTTP 状态代码