[DllImport("wininet.dll", CharSet=CharSet.Auto , SetLastError=true)] public static extern bool InternetGetCookie ( string url, string name, StringBuilder data, ref int dataSize);
[DllImport("wininet.dll", CharSet=CharSet.Auto , SetLastError=
That's it. To wrap the call we define a wrapper function:
private static string RetrieveIECookiesForUrl(string url) { StringBuilder cookieHeader = new StringBuilder(new String(' ', 256), 256); int datasize = cookieHeader.Length; if (!InternetGetCookie(url, null, cookieHeader, ref datasize)) { if (datasize < 0) return String.Empty; cookieHeader = new StringBuilder(datasize); // resize with new datasize InternetGetCookie(url, null, cookieHeader, ref datasize); } return cookieHeader.ToString();}
private
public static CookieContainer GetCookieContainerForUrl(Uri url) { CookieContainer container = new CookieContainer(); string cookieHeaders = RetrieveIECookiesForUrl(url.AbsoluteUri); if (cookieHeaders.Length > 0) { try { container.SetCookies(url, cookieHeaders); } catch (CookieException){} } return container;}
© Copyright 2002-2010, Torsten Rendelmann Page rendered at Saturday, March 13, 2010 7:35:11 PM (W. Europe Standard Time, UTC+01:00)
Like RSS Bandit? Make a donation to help support its development and maintenance. As little as 1€ will help.
SUBSCRIBE RSS GeoURL
newtelligence dasBlog 2.3.9074.18820
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.