IXMLHTTPRequest2::SetCookie method (msxml6.h)

Sets a cookie associated with the specified URL in the HTTP cookie jar.

Syntax

HRESULT SetCookie(
  const XHR_COOKIE *pCookie,
  DWORD            *pdwCookieState
);

Parameters

pCookie

A pointer to an XHR_COOKIE structure that specifies the cookie and properties of the cookie to be associated with the specified URL.

pdwCookieState

A pointer to a value that indicates the cookie state if the call completes successfully.

This parameter can be one of the values from the XHR_COOKIE_STATE enumeration type defined in the Msxml6.h header file.

Value Meaning
XHR_COOKIE_STATE_UNKNOWN
0
Reserved.
XHR_COOKIE_STATE_ACCEPT
1
The cookie was accepted.
XHR_COOKIE_STATE_PROMPT
2
The user is prompted to accept or refuse the cookie.
XHR_COOKIE_STATE_LEASH
3
The cookie is accepted only in the first-party context.
XHR_COOKIE_STATE_DOWNGRADE
4
The cookie was accepted and became session cookie.
XHR_COOKIE_STATE_REJECT
5
The cookie was rejected.

Return value

Returns S_OK on success.

Remarks

The SetCookie method has different behavior for Windows Store apps and Windows desktop applications.

When used in a Windows Store app, the SetCookie method by default sets the cookie as a persistent cookie in the Windows Store app. When the dwFlags member of the XHR_COOKIE has the XHR_COOKIE_IS_SESSION flag set, then the cookie is set only for the current session of the app.

When used in a Windows desktop application, the SetCookie method by default sets a persistent cookie that is system wide and shared by all Windows desktop applications. When the dwFlags member of the XHR_COOKIE has the XHR_COOKIE_IS_SESSION flag set, then the cookie is set only for the current session of the Windows desktop application.

Requirements

Requirement Value
Minimum supported client Windows 8 [desktop apps | UWP apps],MSXML 6.0 and later
Minimum supported server Windows Server 2012 [desktop apps | UWP apps]
Target Platform Windows
Header msxml6.h

See also

GetCookie Method

IXMLHTTPRequest2

XHR_COOKIE Structure

XHR_COOKIE_STATE