Operate cookie

xiaoxiao2021-03-06  65

//Getcookie.cpp

// Need Wininet.lib

#include #include #include #include

Using namespace std;

Void main () {char Szurl [256]; // buffer to hold the url lpstr lpszdata = null; // buffer to hold the cookie data dWord dwsize = 0; // variable to get the buffer size needed // insert code to Retrieve the URL. STRCPY (Szurl, "http://www.9cbs.net"); lpszdata = new char [0]; // First NEW, later explained

retry: // The first call to InternetGetCookie will get the required // buffer size needed to download the cookie data if (InternetGetCookie (szURL, NULL, lpszData, & dwSize)!) {// Check for an insufficient buffer error if (.. GetLastError () == Error_INSUFFICIENT_BUFFER {delete [] lpszdata; // delete just first // allocate the next the next, lpszdata = new char [dwsize]; // Try the call again. Goto retry;} else {/ / INSERT ERROR HANDLING CODE. COUT << "Have Some Error ... / N";}} else {// INSERT CODE to DISPLAY THE COOKIE DATA. COUT << lpszdata << endl; // Release the memory allocated for the Buffer. delete [] lpszdata; // set cookies InternetSetCookie ("http://www.xxxx.com", null, "testdata = test; expires = sat, 01-jan-2005

00:00:00 GMT ");}}

PS:

MSDN is clearly said that LPSZDATA in InternetGetCookie (Szurl, Null, Lpszdata, & DWSIZE) can be null, if lpszdata is null, dwsize will return enough storage of cookies. However, I set up lpszdata = null, DWSIZE = 0 When the function is called, InternetGetCookie (Szurl, Null, Lpszdata, & DWSize) calls directly. . Then it is obvious, LPSZDATA is an empty pointer, which is illegal to its operation.

So, in here, I will become this program.

转载请注明原文地址:https://www.9cbs.com/read-87369.html

New Post(0)