登录网站,然后访问该网站的另一部分

时间:2013-11-12 17:22:47

标签: c++ session curl session-cookies libcurl

我设法使用curl登录我想要的site,然后我尝试使用相同的句柄访问我网站的section,但它无法识别我当前的会话。

我设置curl来处理自己的cookie。

curl_easy_setopt( curlHandleMO, CURLOPT_COOKIEFILE, "" );

我该怎么办?

2 个答案:

答案 0 :(得分:1)

抱歉,我无法添加评论。您可以参考以下问题和答案:How to manage a simple PHP session using C++ cURL (libcurl)

希望这会有所帮助。

答案 1 :(得分:0)

我找到了一个解决方案:我在Firefox中使用FireBug来查看我所需网站上的POST请求是如何看的,我创建了一个标题请求,就像Firefox使用的一样。

struct curl_slist *header=NULL; 
header = curl_slist_append(header,"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
header = curl_slist_append(header,"Accept-Encoding: gzip, deflate");
header = curl_slist_append(header,"Accept-Language: en-us,ro-ro;q=0.8,ro;q=0.6,en-gb;q=0.4,en;q=0.2");
header = curl_slist_append(header,"Connection:  keep-alive");
header = curl_slist_append(header,"Cookie:  __utma=111401936.1442146463.1383320644.1384439040.1384441847.12; __utmz=111401936.1384276584.7.3.utmcsr=expert-monitor.ro|utmccn=(referral)|utmcmd=referral|utmcct=/LexMonitorMBM/comercial/clientextern/autentic.php; Clientextern=klhttfmf1jt2v7c11efcv4lqn4; __utmc=111401936; __utmb=111401936.9.10.1384441847");
header = curl_slist_append(header,"DNT: 1");
header = curl_slist_append(header,"Host:    www.expert-monitor.ro");
header = curl_slist_append(header,"Referer: http://www.expert-monitor.ro/LexMonitorMBM/comercial/clientextern/login.php?succes=0");
header = curl_slist_append(header,"User-Agent:  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");

curl_easy_setopt(curlHandleMO, CURLOPT_HTTPHEADER, header);