wpf - InternetGetCookieEx: not working -
i trying read httponly cookie through wpf, vb.net application. site in question, upon visit, serves 2 cookies: 1 httponly, 1 regular.
i visit site cookie want read via internet explorer. developer tools --> cache --> view cookie information. regular cookie shown there, not httponly 1 (chrome displays both of them correctly. if delete , refresh, site returns 500 error cookie exists).
i run code, based on explained here: c# httponly cookie, follows:
private const internet_cookie_httponly integer = &h2000 <suppressunmanagedcodesecurity, securitycritical, dllimport("wininet.dll", entrypoint:="internetgetcookieexw", setlasterror:=true, charset:=charset.unicode, exactspelling:=true)> friend shared function internetgetcookieex(<[in]> url string, <[in]> cookiename string, <out> cookiedata stringbuilder, <[in], out> byref pchcookiedata uinteger, flags uinteger, reserved intptr) boolean end function <securitycritical()> public shared function getcookie(url string) string dim size integer = 0 dim sb new stringbuilder if internetgetcookieex(url, vbnullstring, nothing, size, internet_cookie_httponly, intptr.zero) '<-- returns false if size <= 0 return nothing end if sb = new stringbuilder(size + 1) if not internetgetcookieex(url, vbnullstring, sb, size, internet_cookie_httponly, intptr.zero) return nothing end if end if dim lasterrorcode = marshal.getlastwin32error '<-- 259 return sb.tostring() end function getcookie("https://www.xyz.com")
i have tried numerous variations of above, result same: lasterrorcode equals 259, in turn translates error_no_more_items, meaning no cookies have been found.
1) site in question in trusted sites zone, doesn't work under protected mode.
2) site under ssl (i not know if has anything).
3) have desperately searched hard disk these cookies' location, no avail.
4) both session cookies (ie no declared expiration date)
5) windows 8 x64, ie10, vs2012
this tiny bit of project milestone has given me countless hours of pain, appreciated.
i willing change methodology give me cookie's value, unless it's overkill (ie winpcap / fiddlercore etc.)
you're correct note code ever work in trusted zone, due q10 here: http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx since cookies aren't shared between ie (which runs in protected mode or appcontainer) , application (which runs @ medium il).
you should pass valid url function (e.g. need @ least trailing slash after hostname); if invalid url works today, might not in future.
also keep in mind you'll ever see ie's persistent cookies code; session cookies isolated per-process, application won't see session cookies ie tab.
Comments
Post a Comment