Re: C++ to read cookies created by local HTML file



Try to replace:

LPSTR lpszData = NULL; // buffer to hold the cookie data
DWORD dwSize=0; // variable to get the buffer size needed

with:

LPSTR lpszData = new char[ 512 ]; // buffer to hold the cookie data
DWORD dwSize=512; // variable to get the buffer size needed

and see what happens.


"Susan Kong" <susan@xxxxxxxxxxxxxx> wrote in message news:%23BS2dzeXGHA.3440@xxxxxxxxxxxxxxxxxxxxxxx
Here is my code, almost the same as MSDN sample.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/win
inet/managing_cookies.asp

programs always goes to this line:
::AfxMessageBox(" other error!"); // this is the line I always get.

Thanks a lot if anybody can give a look through.
BOOL bReturn;

// Create a session cookie.
bReturn = InternetSetCookie("http://www.mysite.com";, NULL,
"TestData = Test");

// Create a persistent cookie.
bReturn = InternetSetCookie("http://www.mysite.com";, NULL,
"TestData = Test; expires = Sat,01-Jan-2006 00:00:00 GMT");


char szURL[256]="http://www.mysite.com";; // 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.

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)
{
// Allocate the necessary buffer.
lpszData = new char[dwSize];

::AfxMessageBox(" ERROR_INSUFFICIENT_BUFFER!");
// Try the call again.
goto retry;
}
else
{
// Insert error handling code.
::AfxMessageBox(" other error!"); // this is the line I always get.
}

}
else
{
// Insert code to display the cookie data.
::AfxMessageBox(lpszData);
// Release the memory allocated for the buffer.
delete[]lpszData;
}

regards,

Susan


"Voidcoder" <voidcoder@xxxxxxxxx> wrote in message
news:e4nSkwUXGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx
Both InternetGetCookie / InternetSetCookie work as expected,
something is wrong with your code.


"Susan Kong" <susan@xxxxxxxxxxxxxx> wrote in message
news:uxACBIUXGHA.3936@xxxxxxxxxxxxxxxxxxxxxxx
HI,

I'm using VS2003, C++. I tried to retrieve the cookies which are created
by
a local HTML file with JavaScript. I read the article:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/win
inet/managing_cookies.asp

and copy the code. Unfortunately, the retrieved cookie strings are
always
empty.

Anyone can shed some light on this or lead me somewhere with C++ CGI
code
stuff?

Thanks in advance.

Susan








.



Relevant Pages

  • Re: C++ to read cookies created by local HTML file
    ... BOOL bReturn; ... // Create a persistent cookie. ... // buffer size needed to download the cookie data. ... I tried to retrieve the cookies which are created ...
    (microsoft.public.vc.mfc)
  • Re: C++ to read cookies created by local HTML file
    ... BOOL bReturn; ... // Create a session cookie. ... // Create a persistent cookie. ...
    (microsoft.public.vc.mfc)
  • Re: Deleting cookies
    ... InternetSetCookie to create a session cookie (that gets deleted when the ... bReturn = InternetSetCookie("http://www.adventure_works.com ", NULL, ... Similar techniques should work from other techniques for cookie creation, ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: [FAQ] How do I retrieve a page from a web site? (Was: PHP behaving like a user using a browser)
    ... contents as an array of lines. ... How do I retrieve a page from a web site that requires a cookie? ... Then, if you are coding in PHP 5, pass the context ...
    (comp.lang.php)
  • PageLoad when BACK is clicked
    ... Basically I think you could do this by JavaScript. ... And then also create a cookie with a timestamp (and set it ... Retrieve the hidden form field value (into a var ... Otherwise reload the page. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)

Quantcast