Skip to content

Instantly share code, notes, and snippets.

@SafeerH
Last active April 23, 2021 19:24
Show Gist options
  • Save SafeerH/0fe492f88f29aee265c47a1dcbe8d6c5 to your computer and use it in GitHub Desktop.
Save SafeerH/0fe492f88f29aee265c47a1dcbe8d6c5 to your computer and use it in GitHub Desktop.
Extract HttpOnly cookies (can be with WebBrowser control)
using System.Runtime.InteropServices;
public class WebHelper {
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref uint pcchCookieData, int dwFlags, IntPtr lpReserved);
const int INTERNET_COOKIE_HTTPONLY = 0x00002000;
public static string GetGlobalCookies(string uri)
{
uint datasize = 1024;
StringBuilder cookieData = new StringBuilder((int)datasize);
if (InternetGetCookieEx(uri, null, cookieData, ref datasize, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero)
&& cookieData.Length > 0)
{
return cookieData.ToString().Replace(';', ',');
}
else
{
return null;
}
}
}
@deadcandle
Copy link

I know it's been 5 years, but it does not work for me. Can you tell me if it's still supposed to be functional, and if so, can u tell me what I am doing wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment