双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

libcurl模拟登陆失败(PHP可以,C++不行,代码差不多)

gzshun gzshun 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
libcurl模拟登陆失败
我现在想登陆某个https网站,用php能成功登陆并取得cookies,但用C++调用libcurl却登陆不了,实现代码基本上一样,求解?
在Windows平台:
php代码(php调用php_curl.dll扩展):
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'https://www.example.net/Login.aspx');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'D:/ck.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'D:/ck.txt');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0");
$rs = curl_exec($ch);
echo $rs;
curl_close($ch);


C++(Qt调用libcurl 7.28.1)代码:
CURL *pcurl;
QString htmlStr;
pcurl = curl_easy_init();

curl_easy_setopt(pcurl, CURLOPT_URL, "https://www.example.net/Login.aspx");
curl_easy_setopt(pcurl, CURLOPT_POSTFIELDS, postdata.toAscii().data());
curl_easy_setopt(pcurl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(pcurl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(pcurl, CURLOPT_COOKIEJAR, m_ckFileName);
curl_easy_setopt(pcurl, CURLOPT_COOKIEFILE, m_ckFileName);
curl_easy_setopt(pcurl, CURLOPT_WRITEFUNCTION, WriteToMem);
curl_easy_setopt(pcurl, CURLOPT_WRITEDATA, (void *)&htmlStr);
curl_easy_setopt(pcurl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(pcurl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0");

if (curl_easy_perform(pcurl) != CURLE_OK)
{
return;
}


提交的表单域完全一样,测试了N天,实在是找不出原因,期间怀疑是代码问题,也重写了好几次,均不行。请大家帮忙下,谢谢?
...全文
评论 7
收藏 已收藏
分享
返回顶部
gzshun
C++ 语言 65,214 成员 250,514 内容