[DllImport("wininet.dll", SetLastError=true)]
public static extern bool InternetGetCookie(
string url, string cookieName, StringBuilder cookieData, ref int size);
Declare Auto Function InternetGetCookie Lib "wininet.dll" ( _
ByVal lpszUrlName As String, ByVal lpszCookieName As String, _
ByVal lpszCookieData As String, ByRef lpdwSize As Integer) As Boolean
None.
You can pass null (Nothing in Visual Basic) to the lpszCookieData parameter to get the require buffer size from the lpdwSize parameter.
Please add some!
private static CookieContainer GetUriCookieContainer(Uri uri)
{
CookieContainer cookies = null;
// Determine the size of the cookie
int datasize = 256;
StringBuilder cookieData = new StringBuilder(datasize);
if (!InternetGetCookie(uri.ToString(), null, cookieData,
ref datasize))
{
if (datasize < 0)
return null;
// Allocate stringbuilder large enough to hold the cookie
cookieData = new StringBuilder(datasize);
if ( !InternetGetCookie(uri.ToString(), null, cookieData,
ref datasize) )
return null;
}
if (cookieData.Length > 0)
{
cookies = new CookieContainer();
cookies.SetCookies(uri, cookieData.ToString().Replace(';', ','));
}
return cookies;
}
Do you know one? Please contribute it!