C # set IE Cookie to automatically open the need to login to the page, such as the QQ panel on the QQ space, he directly into your QQ zone, no need to log in again. This is actually the use of an API function is done, but the setting is very skillful.
///
Set cookies
///
[DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError = True)]
public static extern bool InternetSetCookie (string lpszurlname, String lbszcookiename, string lpszcookiedata);
///
Get cookies
///
[DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError = True)]
public static extern bool InternetGetCookie (
String URL, string name, StringBuilder data, ref int datasize);
static void Main (string[] args)
{
Get the old
StringBuilder cookie = new StringBuilder (New String (', 2048));
int datasize = cookie. Length;
BOOL b= InternetGetCookie ("http://community.csdn.net", null, cookie, ref datasize);
Delete the old
foreach (String fileName in System.IO.Directory.GetFiles (System.Environment.GetFolderPath ( Environment.SpecialFolder.Cookies)))
{
if (Filename.tolower (). IndexOf ("csdn") > 0)
{
System.IO.File.Delete ("Csdn");
}
}
Generate a new
foreach (string C in cookie. ToString (). Split (';'))
{
string[] Item = c.split (' = ');
String name = Item[0];
String value = Item[1] + "; expires=sun,22-feb-2099 00:00:00 GMT";
InternetSetCookie ("Http://community.csdn.net", Name,value);
InternetSetCookie ("Http://forum.csdn.net", name, value);
InternetSetCookie ("Http://webim.csdn.net", name, value);
}
}
Set the cookie information through the code above, save it to the Temp folder, and
A word.
System.Diagnostics.Process.Start ("IEXPLORE. EXE "," webim.csdn.net ");//Invoke IE to open web page
OK will return directly to the successful login page.
Set IE cookie to go