Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: InternetCookieSet InternetCookieGet InternetCookieSetEx InternetCookieGetEx iCookieSet iCookieGet iCookieSetEx iCookieGetEx udfiCookieSetEx udfiCookieGetEx udf_iCookieSetEx udf_iCookieGetEx
The iCookieSet function merely calls the WinInet API function InternetSetCookie: http://msdn.microsoft.com/en-us/library/aa385107(VS.85).aspx
The iCookieGet function merely calls the WinInet API function InternetGetCookie: http://msdn.microsoft.com/en-us/library/aa384710(v=VS.85).aspx
The WinInet API now offers an additional functions called InternetSetCookieEx and InternetGetCookieEx, which allow you to specify some additional flags:
InternetSetCookieEx
InternetGetCookieEx
However below are some UDFs that can be used to call these functions:
#DefineFunction udf_iCookieGetEx( szUrl, szName, iFlag ) ; ~~~~~~~~~~~~~ READ COOKIES ~~~~~~~~~~~~~~~~~~~~~~ ; szUrl = url of cookie you would like to read ; szName = name of cookie to read ; iFlag = can be one of the following values INTERNET_COOKIE_HTTPONLY = 8192 INTERNET_COOKIE_THIRD_PARTY = 32 INTERNET_FLAG_RESTRICTED_ZONE = 131072 ERROR_NO_MORE_ITEMS = 259 If !(iFlag == 0 || iFlag == INTERNET_COOKIE_HTTPONLY || iFlag == INTERNET_COOKIE_THIRD_PARTY || iFlag == INTERNET_FLAG_RESTRICTED_ZONE) Pause('udf_iCookieGetEx Error','Unrecognized iFlag value') Exit EndIf wininet = DllLoad(StrCat(DirWindows(1),'WININET.DLL')) ;BOOL InternetGetCookieEx( ; __in LPCTSTR lpszURL, ; __in LPCTSTR lpszCookieName, ; __inout_opt LPTSTR lpszCookieData, ; __inout LPDWORD lpdwSize, ; __in DWORD dwFlags, ; __in LPVOID lpReserved ;) szCookies = '' iSize = 1024 lpbufdata = BinaryAlloc(iSize) lpbufsize = BinaryAlloc(4) BinaryPoke4(lpbufsize, 0, iSize) If szName == '' ret = DllCall(wininet,long:'InternetGetCookieExA',lpstr:szUrl,lpnull,lpbinary:lpbufdata,lpbinary:lpbufsize, long:iFlag, long:0) Else ret = DllCall(wininet,long:'InternetGetCookieExA',lpstr:szUrl,lpstr:szName,lpbinary:lpbufdata,lpbinary:lpbufsize, long:iFlag, long:0) EndIf If ret == 0 err = DllLastError() If err == ERROR_NO_MORE_ITEMS Then Return szCookies ; Return if no cookied data as specified could be retrieved Pause('InternetGetCookieExA Error', ) Exit Else maxsize = BinaryPeek4(lpbufsize, 0 ) BinaryEodSet( lpbufdata, maxsize ) szCookies = BinaryPeekStr(lpbufdata, 0, maxsize) EndIf BinaryFree(lpbufsize) BinaryFree(lpbufdata) Return szCookies #EndFunction #DefineFunction udf_iCookieSetEx( szUrl, szCookieName, szCookieData, iFlag ) ; ~~~~~~~~~~~~~ SET COOKIES ~~~~~~~~~~~~~~~~~~~~~~ ; szUrl = url of cookie you would like to set ; szCookieName = name of cookie to set ; szCookieData = cookie data ; iFlag = can be one of the following values INTERNET_COOKIE_EVALUATE_P3P = 128 INTERNET_COOKIE_HTTPONLY = 8192 INTERNET_COOKIE_THIRD_PARTY = 32 INTERNET_FLAG_RESTRICTED_ZONE = 131072 If !(iFlag == 0 || iFlag == INTERNET_COOKIE_EVALUATE_P3P || iFlag == INTERNET_COOKIE_HTTPONLY || iFlag == INTERNET_COOKIE_THIRD_PARTY || iFlag == INTERNET_FLAG_RESTRICTED_ZONE) Pause('udf_iCookieSetEx Error','Unrecognized iFlag value') Exit EndIf wininet = DllLoad(StrCat(DirWindows(1),'WININET.DLL')) ; DWORD InternetSetCookieEx( ; __in LPCTSTR lpszURL, ; __in LPCTSTR lpszCookieName, ; __in LPCTSTR lpszCookieData, ; __in DWORD dwFlags, ; __in DWORD_PTR dwReserved ;) If szCookieName == '' ret = DllCall(wininet,long:'InternetSetCookieExA',lpstr:szUrl,lpnull,lpstr:szCookieData,long:iFlag,long:0) Else ret = DllCall(wininet,long:'InternetSetCookieExA',lpstr:szUrl,lpstr:szCookieName,lpstr:szCookieData,long:iFlag,long:0) EndIf If ret == 0 Pause('InternetSetCookieExA Error', DllLastError() ) Exit EndIf Return ret #EndFunction szUrl = 'http://google.com' szName = '' ; read all cookies iFlag = 8192 ;INTERNET_COOKIE_HTTPONLY ;Read all cookies cookielist = udf_iCookieGetEx( szUrl, '', iFlag )
Article ID: W17621
Filename: InternetCookieSetEx and InternetCookieGetEx.txt
File Created: 2010:06:04:08:42:44
Last Updated: 2010:06:04:08:42:44