php - 为什么 curl_exec 不输出数据?
问题描述
header('Content-type: text/html; charset=utf-8');
require 'phpQuery/phpQuery.php';
function debug($arr) {
echo '<pre>'. print_r($arr, true). '</pre>';
}
function getContent($url, $data = []) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . '/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . '/cookie.txt');
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
$urlAuth = 'https://auth.mail.ru/cgi-bin/auth';
$url = 'https://wf.mail.ru/officers';
$auth_data = [
'Page' => 'https://wf.mail.ru/',
'FakeAuthPage' => 'https://wf.mail.ru/auth',
'Login' => 'MyNail',
'Password' => 'MyPass',
'do_login' => ''
];
$data = getContent($urlAuth, $auth_data);
$data = getContent($url);
debug($data);
在 cookie 中,数据写得很好,但是当我转到 wf.mail.ru/officers 页面时,没有显示内容。告诉我错误是什么。感谢。
添加了错误输出,错误:来自服务器的空回复。但为什么答案是空的?
我添加到 getContent()
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
if (!empty($data))
curl_setopt($ch, CURLOPT_POST, true);
else
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
解决方案
推荐阅读
- spring - Spring集成:使用引用而不是值作为属性?
- html - 如何让我的图标和横幅图像对齐。
- javascript - 从字符串中提取数字并删除小数并将其添加到字符串中
- r - 使用 np 和降雪并行估计多个非参数模型
- single-sign-on - 如何将 CA SSO(CA Siteminder) SAML IdP 配置为 asp.net azure web 应用程序?
- r - ifelse() 没有在 R 中正确存储值
- php - 手动安装mysql后phpmyadmin访问被拒绝
- ajax - 为什么我无法 ajax 更新 Primefaces ContextMenu(用于 DataTable)?
- c# - 检查 API 是否存在,应该是 Get 还是 Post 方法?
- angular - 等待条件失败后量角器重试函数