Use the webbowser control once to open the webpage and then read the cookie.
Use the wininet. dll component to read the cookie:
[DllImport ("wininet. dll", CharSet = CharSet. Auto, SetLastError = true)]
Static extern bool InternetGetCookieEx (string pchURL, string pchCookieName, StringBuilder pchCookieData, ref System. UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved );
Private static string GetCookies (string url)
{
Uint datasize = 1024;
StringBuilder cookieData = new StringBuilder (int) datasize );
If (! InternetGetCookieEx (url, null, cookieData, ref datasize, 0x2000, IntPtr. Zero ))
{
If (datasize <0)
Return null;
CookieData = new StringBuilder (int) datasize );
If (! InternetGetCookieEx (url, null, cookieData, ref datasize, 0x00002000, IntPtr. Zero ))
Return null;
}
Return cookieData. ToString ();
}
Note: During cookie Resolution:
If the cookie value contains commas (,), % 2C can be replaced.
Example:
CookieContainer cookieContainer = new CookieContainer ();
String cookieStr = GetCookies ("http://abc.com /");
String [] cookstr = cookieStr. Split (';');
Foreach (string str in cookstr)
{
String [] data = str. Split ('= ');
If (data [1]. Trim (). ToString (). IndexOf (',')! =-1)
{
Data [1] = data [1]. Trim (). ToString (). Replace (",", "% 2C ");
}
Cookie ck = new Cookie (data [0]. Trim (). ToString (), data [1]. Trim (). ToString ());
CookieContainer. Add (new Uri ("http://abc.com/"), ck );
}
End.