Php Curl 和批处理

问题描述 投票:0回答:1

我尝试转换此行命令(有效):

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();
        

我该怎么办?

谢谢

php batch-file curl dos
1个回答
0
投票

试试看:

$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 状态代码

© www.soinside.com 2019 - 2024. All rights reserved.