【发布时间】:2017-01-16 17:56:07
【问题描述】:
我正在尝试使用 PHP 和 CURL 从网页中获取 cookie 文件:https://www.receita.fazenda.gov.br/Aplicacoes/SSL/ATCTA/CPF/ConsultaSituacao/ConsultaPublica.asp
但是在第一次之后,我不能再接受它了,cookie 仅在 1º 连接中的“响应标题”中可用,在 1º 连接之后它就不是更多了。
我尝试发出 CURL 请求清理缓存或避开缓存,但没有成功。
所以当我尝试在浏览器中执行此操作时,我注意到的是,在我清理缓存时,我可以在“响应标题”中看到 cookie,我如何使用 PHP + CURL 来执行此操作,我需要获取cookie?
谢谢!
代码:
define('COOKIELOCAL', realpath('./').'/');
$ch = curl_init("https://www.receita.fazenda.gov.br/Aplicacoes/SSL/ATCTA/CPF/ConsultaPublica.asp");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
/* trying to clean the cache */
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Pragma: no-cache",
"Cache-control: no-cache"
));
$result = curl_exec($ch);
echo 'Cookie...........:' . file_get_contents($cookieFile); // Empty cookie file here until now
【问题讨论】: