curl获得cookie数据<转>

curl获得cookie数据<转>,第1张

概述  CURL *curl; CURLcode res; struct curl_slist *headers = NULL; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { //初始化cookie引擎 curl
  CURL *curl;    CURLcode res;    struct curl_sList *headers = NulL;    curl_global_init(CURL_GLOBAL_ALL);    curl = curl_easy_init();    if(curl)    {        //初始化cookie引擎        curl_easy_setopt(curl,CURLOPT_cookiefile,"");    //初始化cookie引擎,才能正确接收到cookie数据.        curl_easy_setopt(curl,CURLOPT_FolLOWLOCATION,1L);         curl_easy_setopt(curl,CURLOPT_URL,"https://passport.csdn.net/account/login");        curl_easy_setopt(curl,CURLOPT_cookieJAR,"cookie_open.txt");        //把服务器发过来的cookie保存到cookie_open.txt          curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,0L);          curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST,0L);           //file *bodyfile;          //bodyfile = fopen("open.HTML","w");           //curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write_data);  //写数据的回调函数存文件        //curl_easy_setopt(curl,CURLOPT_WRITEDATA,bodyfile);         string content;        //设置回调函数        curl_easy_setopt(curl,writer);        curl_easy_setopt(curl,&content);                  //执行http请求        res = curl_easy_perform(curl);         //如果执行成功,        if(res ==  CURLE_OK)        {            struct curl_sList *cookies = NulL;              curl_easy_getinfo(curl,CURliNFO_cookieList,&cookies);       //获得cookie数据               int i=1;              while (cookies)             {                  TRACE("[%d]: %s\n",i,cookies->data);                  cookies = cookies->next;                  i++;              }          }         //再次请求的地址        char *token_url="https://passport.csdn.net/account/login";         //释放资源         //fclose(bodyfile);        curl_sList_free_all(headers);        curl_easy_cleanup(curl);    }     curl_global_cleanup();

源地址:https://blog.csdn.net/qing666888/article/details/43623431

总结

以上是内存溢出为你收集整理的curl获得cookie数据<转>全部内容,希望文章能够帮你解决curl获得cookie数据<转>所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1020906.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存