共用方式為


CInternetSession::GetCookie

This member function implements the behavior of the Win32 function InternetGetCookie, as described in the Windows SDK.

static BOOL GetCookie(
   LPCTSTR pstrUrl,
   LPCTSTR pstrCookieName,
   LPTSTR pstrCookieData,
   DWORD dwBufLen 
);
static BOOL GetCookie(
   LPCTSTR pstrUrl,
   LPCTSTR pstrCookieName,
   CString& strCookieData 
);

Parameters

  • pstrUrl
    A pointer to a string containing the URL.

  • pstrCookieName
    A pointer to a string containing the name of the cookie to get for the specified URL.

  • pstrCookieData
    In the first overload, a pointer to a string containing the address of the buffer that receives the cookie data. This value can be NULL. In the second overload, a reference to a CString object to receive the cookie data.

  • dwBufLen
    The variable specifying the size of the pstrCookieData buffer. If the function succeeds, the buffer receives the amount of data copied to the pstrCookieData buffer. If pstrCookieData is NULL, this parameter receives a value that specifies the size of the buffer necessary to copy all the cookie data.

Return Value

Returns TRUE if successful, or FALSE otherwise. If the call fails, call the Win32 function GetLastError to determine the cause of the error. The following error values apply:

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

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

Remarks

In the second overload, MFC retrieves the cookie data into the supplied CString object.

Requirements

Header: afxinet.h

See Also

Reference

CInternetSession::GetCookieLength

CInternetSession::SetCookie