方法一:

CInternetSession::GetCookie

This member function implements the behavior of the Win32 function InternetGetCookie, as
described in the Windows SDK.

static BOOL GetCookie( 
LPCTSTR pstrUrl, 
LPCTSTR pstrCookieName, 
LPTSTR pstrCookieData, 
DWORD dwBufLen 
); 
static BOOL GetCookie( 
LPCTSTR pstrUrl, 
LPCTSTR pstrCookieName, 
CString& strCookieData 
);

http://msdn.microsoft.com/en-us/library/vstudio/cff9kt47(v=vs.120).aspx

实现:

char * pszURL = "http://www.baidu.com/";
CInternetSession::GetCookie(pszURL, "", strCookie);
printf("%s\n", strCookie);

方法二:

InternetGetCookie

BOOL InternetGetCookie(
_In_     LPCTSTR lpszUrl,
_In_     LPCTSTR lpszCookieName,
_Out_    LPTSTR lpszCookieData,
_Inout_  LPDWORD lpdwSize
);

http://msdn.microsoft.com/en-us/library/ie/aa384710(v=vs.85).aspx

实现:

LPDWORD lpdwSize = new DWORD;
char strCookie_two[100] = {0};
InternetGetCookie(pszURL, NULL, strCookie_two, lpdwSize);
InternetGetCookie(pszURL, NULL, strCookie_two, lpdwSize);
printf("%s\n", strCookie_two);

方法三:

QueryInfo

	CInternetSession session("HttpClient");
CHttpFile* pfile = (CHttpFile *)session.OpenURL(pszURL);
CString strCookie_three;
pfile->QueryInfo(HTTP_QUERY_SET_COOKIE, strCookie_three);
printf("%s\n", strCookie_three);

Managing Cookies

//获取cookies的几种方法
#include <afxinet.h>
#include <atlstr.h>
#include <cstdio> int main()
{
char * pszURL = "http://blog.csdn.net/x_iya"; //方法一
printf("方法一:\n");
CString strCookie_one;
CInternetSession::GetCookie(pszURL, "", strCookie_one);
printf("%s\n", strCookie_one); //方法二
printf("方法二:\n");
LPDWORD lpdwSize = new DWORD;
char strCookie_two[100] = {0};
InternetGetCookie(pszURL, NULL, strCookie_two, lpdwSize);
InternetGetCookie(pszURL, NULL, strCookie_two, lpdwSize);
printf("%s\n", strCookie_two); //方法三
printf("方法三:\n");
CInternetSession session("HttpClient");
CHttpFile* pfile = (CHttpFile *)session.OpenURL(pszURL);
CString strCookie_three;
pfile->QueryInfo(HTTP_QUERY_SET_COOKIE, strCookie_three);
printf("%s\n", strCookie_three);
return 0;
}

VC获取cookies的几种方法的更多相关文章

  1. VC++获取IDC_EDIT的7种方法

    VC++获取IDC_EDIT的7种方法 http://blog.csdn.net/baizengfei/article/details/7997618 //第一种方法 int number1, num ...

  2. PHP中获取星期的几种方法

    PHP中获取星期的几种方法   PHP星期几获取代码: 1 date(l); 2 //data就可以获取英文的星期比如Sunday 3 date(w); 4 //这个可以获取数字星期比如123,注意0 ...

  3. C#获取当前路径的7种方法

    总结C#获取当前路径的7种方法 C#获取当前路径的方法如下: 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName ...

  4. Java获取随机数的几种方法

    Java获取随机数的几种方法 .使用org.apache.commons.lang.RandomStringUtils.randomAlphanumeric()取数字字母随机10位; //取得一个3位 ...

  5. spring 获取 WebApplicationContext的几种方法

    spring 获取 WebApplicationContext的几种方法 使用ContextLoader WebApplicationContext webApplicationContext = C ...

  6. Struts2 后台获取路径的几种方法

    Struts2 后台获取路径的几种方法 package actions.app; import java.io.File; import org.apache.struts2.ServletActio ...

  7. 体温数据上传程序开发+获取时间的三种方法+DB Browser下载及安装

    今天开始了体温上传程序的开发 今日所学: 获取时间 (21条消息) (转)安卓获取时间的三种方法_sharpeha的博客-CSDN博客_安卓获取时间 DB Browser安装教程 (20条消息) sq ...

  8. VC调用javascript的几种方法

    第一种:通过execScript调用.这种方法,虽然操作方便,但不能获取返回值.m_spHtmlDoc->get_parentWindow(&m_pHtmlWindow);VARIANT ...

  9. VC++ 响应回车键的2种方法

    众所周知,VC++响应回车键经常用的方法是利用 BOOL PreTranslateMessage(MSG* pMsg) 截取回车键消息,如: if (pMsg->message == WM_KE ...

随机推荐

  1. Spring 配置内容外部化

  2. git submodule 管理子项目

    使用场景 拆分项目,当项目越来越大之后,我们希望 子模块 可以单独管理,并由 专门 的人去维护,这个时候只可以使用 git submodule 去完成. 常用命令 git clone <repo ...

  3. Redhat6 RPM 软件管理常用命令汇总

    软件的安装时操作系统管理的基础,与Windows不同,Linux的软件管理有很多种方式,Redhat的最常用的是RPM方式,安装集成在光盘中的RPM包.这种方式比Windows平台的软件管理更加便捷( ...

  4. cc协议(知识共享,Creative Commons),程序员的基础守则之一

    知识共享 我在浏览git开源代码的时候,浏览到一句话: 版权声明:本文为CSDN博主「...」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明. 原文链接:http ...

  5. Have Fun with Numbers

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

  6. 【记】本地远程连接VM VirtualBox中虚拟机Centos6的数据库MySQL

    目标:远程连接虚拟机中的MySQL 效果图如下 1. VBox设置好端口转发 具体步骤请看 VM VirtualBox 网络地址转换(NAT)使用详解 2. MySQL授权 如果这时我们就去远程连接M ...

  7. Spring中常见的设计模式——适配器模式

    一.适配器模式的应用场景 适配器模式(Adapter Pattern)是指将一个类的接口转换成用户期待的另一个接口,使原本接口不兼容的类可以一起工作,属于构造设计模式. 适配器适用于以下几种业务场景: ...

  8. Mybatis Plugin 以及Druid Filer 改写SQL

    背景 工作中偶尔会碰到需要统一修改SQL的情况,例如有以下表结构: CREATE TABLE `test_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, ` ...

  9. 通过自己实现接口来加深理解SpringMVC的执行流程

    功能介绍 上篇文章[从源码角度了解SpringMVC的执行流程]通过接口源码向大家介绍了SpringMVC的执行流程,主要偏重于源码.这篇文件我们来自己实现那几个关键接口,来真实体验下SpringMV ...

  10. max_element( )

    直接用这个函数 , 会比自己写个for 判断快的多了 . position=max_element(a,a+n)-a; position  代表找到最大元素的位置 , max_element( ) 的 ...