c++ curl 登陆renren.com (cookie的使用)
2012-05-28 20:39
225 查看
size_t write_callback( void *ptr, size_t size, size_t nmemb, void *stream ) { int len = size * nmemb; int written = len; if ( access( (char*)stream, 0 ) == -1 ) { fp = fopen( (char*) stream, "wb" ); } else { fp = fopen( (char*) stream, "ab" ); } if (fp) { fwrite( ptr, size, nmemb, fp ); } return written; } int PostUrlchar* url, void *savepath) { // 初始化libcurl CURLcode return_code; return_code = curl_global_init(CURL_GLOBAL_WIN32); if (CURLE_OK != return_code) return 0; CURL *curl_handle; CURLcode res; curl_handle = curl_easy_init(); curl_easy_setopt(curl_handle, CURLOPT_URL, url); curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl_handle, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"); curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "cookie.txt"); curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "cookie.txt"); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt( curl_handle, CURLOPT_WRITEDATA, savepath ); curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS,postLoginData); res = curl_easy_perform(curl_handle); curl_easy_cleanup(curl_handle); curl_global_cleanup(); if (res == CURLE_OK) { return 1; } return 0; } int GetUrl(string url,void *buffer) { // 初始化libcurl CURLcode return_code; return_code = curl_global_init(CURL_GLOBAL_WIN32); if (CURLE_OK != return_code) return 0; CURL *easy_handle = curl_easy_init(); if (NULL == easy_handle) { curl_global_cleanup(); return 0; } // 设置easy handle属性 curl_easy_setopt(easy_handle, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"); curl_easy_setopt(easy_handle,CURLOPT_FOLLOWLOCATION,TRUE); curl_easy_setopt(easy_handle, CURLOPT_URL, url.c_str()); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"cookie.txt"); curl_easy_setopt(easy_handle, CURLOPT_COOKIEJAR, "cookie.txt"); curl_easy_perform(easy_handle); curl_easy_cleanup(easy_handle); curl_global_cleanup(); return 1; }
1.先post登陆到url。
2.再访问自己的主页。
可以使用Wireshark抓取各个web地址,及post具体格式的数据。
相关文章推荐
- ASP.NET使用Cookie简单实现记住登陆状态功能
- 使用cookie实现统计访问者登陆次数
- Servlet学习笔记(五)-----使用Servlet处理用户注册和登陆(使用了Cookie)
- 使用OKHttp模拟登陆知乎,兼谈OKHttp中Cookie的使用!
- js使用cookie保存登陆信息
- 基于cookie使用过滤器实现客户每次访问自登陆一次
- 使用cookie登陆知乎
- 使用OKHttp模拟登陆知乎,兼谈OKHttp中Cookie的使用!
- python使用cookie模拟登陆
- 使用http.cookiejar生产Cookie模拟用户登陆
- 使用Cookie登陆,保存Cookie,读取Cookie(C#)
- java的web项目中使用cookie保存用户登陆信息
- goahead 的认证和自定义登陆页面的cookie使用
- 使用OKHttp模拟登陆知乎,兼谈OKHttp中Cookie的使用!
- C#如何HttpWebRequest模拟登陆,获取服务端返回Cookie以便登录请求后使用
- js使用cookie保存登陆信息
- httpclient模拟登陆(使用js设置cookie)
- 6.如何使用官方提供的nuget包实现cookie登陆
- 使用OKHttp模拟登陆知乎,兼谈OKHttp中Cookie的使用!
- python使用cookie登陆网页