php - PHP Curl cookie 不同的页面
问题描述
我有一个用 PHP 编写的 CURL 机器人,它登录到一个站点并从另一个站点的页面下载数据,该页面可以从第一个站点访问。这是我的代码:
登录
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1800);
curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
curl_setopt($ch, CURLOPT_URL, "https://www.aaaaa.bbbb.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $strCookieRandName);
curl_setopt($ch, CURLOPT_COOKIEFILE, $strCookieRandName);
登录后
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1800);
curl_setopt($ch, CURLOPT_TIMEOUT, 3600);
curl_setopt($ch, CURLOPT_URL, "https://www1.aaaaa.bbbb.com/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $strCookieRandName);
curl_setopt($ch, CURLOPT_COOKIEFILE, $strCookieRandName);
会话 cookie 由https://www.aaaaa.bbbb.com/创建,但第二页是https://www1.aaaaa.bbbb.com/
在浏览器中完美运行,通过 curl 第二页告诉我没有登录。你有什么想法吗?Tks
解决方案
推荐阅读
- java - 由于这个错误,我无法完成这个冒险故事
- python - 我们如何在 jsonpath_ng python 中使用正则表达式过滤器,它将 / 视为 SORT 方向。有什么选择吗?
- python - 如何在 Qt 样式表中设置相对路径?
- excel - 在#N/A 值上使用开关公式
- python - 添加开始时间和结束时间来抓取雅虎未婚夫
- html - 不正确的 CSS 选择器规则?
- python - 此 Regex 模式匹配的时间复杂度是多少?
- flutter - 选择时选择芯片颜色不变
- python - 如何根据不同的条件为熊猫数据框中的特定列赋值?
- flutter - 我想在共享首选项中保留 Web 视图