InternetGetCookie Function Home
InternetGetCookie Function

Retrieves the cookie for the specified URL.

Syntax

BOOL InternetGetCookie(
  __in     LPCTSTR lpszUrl,
  __in     LPCTSTR lpszCookieName,
  __out    LPTSTR lpszCookieData,
  __inout  LPDWORD lpdwSize
);


Parameters

lpszUrl [in]

A pointer to a null-terminated string that specifies the URL for which cookies are to be retrieved.

lpszCookieName [in]

Not implemented.

lpszCookieData [out]

A pointer to a buffer that receives the cookie data. This parameter can be NULL.

lpdwSize [in, out]

A pointer to a variable that specifies the size of the lpszCookieData parameter buffer, in TCHARs. If the function succeeds, the buffer receives the amount of data copied to the lpszCookieData buffer. If lpszCookieData is NULL, this parameter receives a value that specifies the size of the buffer necessary to copy all the cookie data, expressed as a byte count.

Return Value

If the function succeeds, the function returns TRUE.

If the function fails, it returns FALSE. To get extended error data, call GetLastError.

The following error values apply to InternetGetCookie.

Return codeDescription
ERROR_NO_MORE_ITEMS

There is no cookie for the specified URL and all its parents.

ERROR_INSUFFICIENT_BUFFER

The value passed in lpdwSize is insufficient to copy all the cookie data. The value returned in lpdwSize is the size of the buffer necessary to get all the data.

ERROR_INVALID_PARAMETER

One or more of the parameters is invalid.

The lpszUrl parameter is NULL.

 

Remarks

InternetGetCookie does not require a call to InternetOpen. InternetGetCookie checks in the windows\cookies directory for persistent cookies that have an expiration date set sometime in the future. InternetGetCookie also searches memory for any session cookies, that is, cookies that do not have an expiration date that were created in the same process by InternetSetCookie, because these cookies are not written to any files. Rules for creating cookie files are internal to the system and can change in the future.

As noted in HTTP Cookies, InternetGetCookie does not return cookies that the server marked as non-scriptable with the "HttpOnly" attribute in the Set-Cookie header.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
VersionInternet Explorer 3.0 or later
HeaderWininet.h
LibraryWininet.lib
DLLWininet.dll
Unicode and ANSI namesInternetGetCookieW (Unicode) and InternetGetCookieA (ANSI)

See Also

HTTP Cookies
Managing Cookies
WinINet Functions
InternetGetCookieEx
InternetSetCookie
InternetSetCookieEx

Send comments about this topic to Microsoft

Build date: 11/19/2009

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View