www.pudn.com > CookieTest.rar > CookieTest.cpp, change:2010-01-12,size:944b


// test.cpp : 定义控制台应用程序的入口点。 
#include "stdafx.h" 
#include <Windows.h> 
#include <WinInet.h> 
#include <iostream> 
using namespace std; 
 
int main(int argc, char* argv[]) 
{ 
 
	char url[] = "http://www.pudn.com"; 
 
	int ilen = strlen(url); 
	if (ilen < 256) 
	{ 
		char szURL[256] = {0}; 
		strncpy(szURL, url, ilen); 
		LPSTR lpszData = NULL;    
		DWORD dwSize = 0;  
		lpszData = new char[1]; 
		memset(lpszData,0,1); 
retry: 
		if (!InternetGetCookie(szURL, "", lpszData, &dwSize)) 
		{ 
			if (GetLastError()== ERROR_INSUFFICIENT_BUFFER) 
			{ 
				delete []lpszData; 
				lpszData = new char[dwSize+1]; 
				memset(lpszData,0,dwSize+1); 
				goto retry; 
			} 
			else 
			{ 
				cout<<"cookie为空!"; 
			} 
		} 
		else 
		{ 
			cout<<"获取cookie成功!"<<endl; 
		} 
		cout<<"您输入网址的cookie为:"<<endl<< lpszData <<endl; 
		delete[]lpszData; 
	} 
	else 
	{ 
		cout <<"参数超长!"; 
		return -1; 
	} 
 
	return 0; 
}