注:此方法获取的cookie仅限于使用IE访问过的网站 #include windows.h#include assert.h#include WinInet.h#pragma comment(lib,"winInet.lib")#include iostreamusing namespace std;//------------------------------------------------
注:此方法获取的cookie仅限于使用IE访问过的网站
#include <windows.h>
#include <assert.h>
#include <WinInet.h>
#pragma comment(lib,"winInet.lib")
#include <iostream>
using namespace std;
//---------------------------------------------------------------------------
class Cookie
{
LPSTR s_lpszCookie;
DWORD s_dwSize;
public:
Cookie():s_lpszCookie(NULL),s_dwSize(0)
{
}
virtual ~Cookie()
{
if(s_lpszCookie)
{
delete [] s_lpszCookie;
s_lpszCookie=NULL;
}
}
bool Execute(LPSTR lpszUrl)
{
if(InternetGetCookie(lpszUrl,NULL,NULL,&s_dwSize))
{
s_lpszCookie=new char[s_dwSize];
assert(s_lpszCookie!=NULL);
if(InternetGetCookie(lpszUrl,NULL,s_lpszCookie,&s_dwSize))
return true;
}
return false;
}
const LPSTR GetCookie()
{
return s_lpszCookie;
}
const DWORD GetCookieSize()
{
return s_dwSize;
}
};
int main(int argc, char* argv[])
{
char szURL[]="";
Cookie cookie;
if(cookie.Execute(szURL))
{
cout<<cookie.GetCookie()<<endl;
}
else
cout<<"Cookie为空"<<endl;
cin.get();
return 0;
}