Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear cookie through WinINet function?

Using WinINet InternetGetCookie and InternetSetCookie functions, it's pretty straightforward to get and set cookie inside the application which makes a web request through WinINet.

However, I could not so far find a way to clear cookie.

Calling InternetSetCookie with blank data (either L"" or NULL) does not help (tried both with and without specifying the cookie name).

Tried FindFirst/NextUrlCacheGroup, DeleteUrlCacheGroup, and also FindFirst/NextUrlCacheEntry, DeleteUrlCacheEntry combinations. Still no luck.

Any ideas?

like image 261
Kei Avatar asked Feb 24 '23 21:02

Kei


1 Answers

Kei,

I had the same problem and a colleague of mine just helped me solve it. You need to call:

InternetSetOption(0, 42, NULL, 0);

The answer is taken from here.

This did the trick for my app and I hope it will work for you also.

Edit:
The "42" value in the function call stands for the "INTERNET_OPTION_END_BROWSER_SESSION" flag, which "Flushes entries not in use from the password cache on the hard disk drive. Also resets the cache time used when the synchronization mode is once-per-session. No buffer is required for this option. This is used by InternetSetOption." ( http://msdn.microsoft.com/en-us/library/aa385328%28v=vs.85%29.aspx )

like image 50
vladges Avatar answered Mar 04 '23 01:03

vladges