C++ 如何获取cookie

 

//  win32_cui.cpp : 定义控制台应用程序的入口点。
//

#include 
" stdafx.h "
#include 
< Windows.h >
#include 
< WinInet.h >
#include 
< iostream >
using   namespace  std;

int  _tmain( int  argc,  char *  argv[])
{
    
if  (argc  != 2
    {
        cout 
<<   " Please useing:test http://www.google.cn " ;
        cout 
<<  endl;
    }
    
else
    {
        
int  ilen = strlen(argv[ 1 ]);
        
if  (ilen < 256 )
        {
            
char  szURL[ 256 ] = { 0 };
            strncpy(szURL,argv[
1 ],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 ;
}

 

 

你可能感兴趣的:(cookie)