Wininet.dll function Library: Cookies that do not expire

Source: Internet
Author: User
Tags foreach set cookie split

The

Wininet.dll contains many Win32 and network-related functions, including internet,ftp, below, which shows a cookie for IE. For example, CSDN login information can be saved for 2 weeks, you log in after the system time to 2 weeks, the landing information is invalid, use InternetSetCookie can set their own expiration date. First in IE login, log in to choose information to save 2 weeks, and then run the following code, after the operation you can adjust the date to 2010 see Effect:

Using System;
Using System.Text;
Using System.Runtime.InteropServices;
    Namespace ConsoleApplication1 {class Program {///<summary>///set Cookie///</summary> [DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool InternetSetCookie (ST
    Ring Lpszurlname, String lbszcookiename, string lpszcookiedata); <summary>///Get Cookie///</summary> [DllImport ("Wininet.dll", CharSet = CharSet.Auto, Setlas  Terror = 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://www.bianceng.cn", null, cookie, ref datasize); Deletes 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://www.bianceng.cn", Name,value);
        InternetSetCookie ("Http://forum.csdn.net", name, value);
      InternetSetCookie ("Http://webim.csdn.net", name, value); }     }   } }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.