无法使用PHP Curl调用基于浏览器的请求

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

如果我们在浏览器中调用相同的URL,则它将自动下载CSV文件。因此,我想要使用PHP curl的相同功能将CSV文件保存在同一文件夹下。但这每次都会给我带来空洞的结果。能否请您指导我下面的代码有什么问题?

$url="https://www.centrano.com/[email protected]&password=dHB3L1FpTEg1c2pLZ29SUkdnUWcwWTFqN2RIamQx";

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
$agent= "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_VERBOSE, true); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100000); //time out of 15 seconds
$output = curl_exec($ch); 
print_r($output);
curl_close($ch);
php curl file-get-contents php-curl
1个回答
0
投票

添加以下两个CURL选项以使其起作用:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);                                 
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');   

页面多次重定向到同一主机,并要求会话cookie保持存在(因此,将它们存储在cookie jar中。

还:立即更改您的centrano.com帐户密码!尽管它有助于解决此问题,但将其公开通常不是一个好主意。

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