WinINet Functions


InternetGetCookieEx Function

The InternetGetCookieEx function retrieves data stored in cookies associated with a specified URL. Unlike InternetGetCookie, InternetGetCookieEx can be used to restrict data retrieved to a single cookie name or, by policy, associated with untrusted sites or third-party cookies.

Syntax

C++
BOOL InternetGetCookieEx(
  __in         LPCTSTR pchURL,
  __in         LPCTSTR pchCookieName,
  __inout_opt  LPTSTR pchCookieData,
  __inout      LPDWORD pcchCookieData,
  __in         DWORD dwFlags,
  __in         LPVOID lpReserved
);

Parameters

pchURL [in]

A pointer to a null-terminated string that contains the URL with which the cookie to retrieve is associated. This parameter cannot be NULL or InternetGetCookieEx fails and returns an ERROR_INVALID_PARAMETER error.

pchCookieName [in]

A pointer to a null-terminated string that contains the name of the cookie to retrieve. This name is case-sensitive.

pchCookieData [in, out, optional]

A pointer to a buffer to receive the cookie data.

pcchCookieData [in, out]

A pointer to a DWORD variable.

On entry, the variable must contain the size, in TCHARs, of the buffer pointed to by the pchCookieData parameter.

On exit, if the function is successful, this variable contains the number of TCHARs of cookie data copied into the buffer. If the function fails with an error of ERROR_INSUFFICIENT_BUFFER, the variable contains the size, in TCHARs, of buffer required to receive the cookie data.

This parameter cannot be NULL or InternetGetCookieEx fails and returns an ERROR_INVALID_PARAMETER error.

dwFlags [in]

A flag that controls how the function retrieves cookie data. This parameter can be one of the following values.

ValueMeaning
INTERNET_COOKIE_HTTPONLY

Enables the retrieval of cookies that are marked as “HTTPOnly”.

Do not use this flag if you expose a scriptable interface, because this has security implications. It is imperative that you use this flag only if you can guarantee that you will never expose the cookie to third-party code by way of an extensibility mechanism you provide.

Version:  Requires Internet Explorer 8.0 or later.
INTERNET_COOKIE_FULL_DETAIL

Enables the retrieval of extended cookie information. The format of the returned cookie string is as follows: n=[name]; v=[value]; d=[domain]; p=[path][; httponly][; secure][; session], where items in square brackets are optional fields. The "httponly" field is present if the cookie was set by the server as HTTPOnly. The "secure" field is present only if the server set the cookie by way of an HTTPS response. The "session" field is present if the server set the cookie without an "expires" property (see HTTP Cookies).

Version:  Requires Internet Explorer 8.0 or later.
INTERNET_COOKIE_THIRD_PARTY

Retrieves only third-party cookies if policy explicitly allows all cookies for the specified URL to be retrieved.

INTERNET_FLAG_RESTRICTED_ZONE

Retrieves only cookies that would be allowed if the specified URL were untrusted; that is, if it belonged to the URLZONE_UNTRUSTED zone.

 

lpReserved [in]

Reserved for future use. Set to NULL.

Return Value

If the function succeeds, the function returns TRUE.

If the function fails, it returns FALSE. To get a specific error value, call GetLastError.

The following error codes may be returned.

Return codeDescription
ERROR_INSUFFICIENT_BUFFER

Returned if cookie data retrieved is larger than the buffer size pointed to by the pcchCookieData parameter or if that parameter is NULL.

ERROR_INVALID_PARAMETER

Returned if either the pchURL or the pcchCookieData parameter is NULL.

ERROR_NO_MORE_ITEMS

Returned if no cookied data as specified could be retrieved.

 

Requirements

Minimum supported clientWindows XP
Minimum supported serverWindows Server 2003
HeaderWininet.h
LibraryWininet.lib
DLLWininet.dll
Unicode and ANSI namesInternetGetCookieExW (Unicode) and InternetGetCookieExA (ANSI)

See Also

HTTP Cookies
Managing Cookies
WinINet Functions
InternetGetCookie
InternetSetCookie
InternetSetCookieEx

Send comments about this topic to Microsoft

Build date: 10/8/2009

Tags :


Community Content

Anonymous_65463565
How to handle case when pchCookieData is NULL
When pchCookieData is NULL and pcchCookieData is not NULL, InternetGetCookieEx will return TRUE and set last error to ERROR_INSUFFICIENT_BUFFER.
Tags :

Thomas Lee
INTERNET_COOKIE_FULL_DETAIL does not exist
This flag does not exist in the Windows 7 RC platform SDK. This is a documentation bug.
Tags : contentbug

Page view tracker