Wininet. dll function library: cookie that does not expire (you can also set the webbrowser cookie)

Source: Internet
Author: User
Using System;

Using System. text;

Using System. runtime. interopservices;

Namespace Leleapplication1

{

Class Program

{

///   <Summary>

/// Set cookie

///   </Summary>

[Dllimport ( " Wininet. dll " , Charset = Charset. Auto, setlasterror =   True )]

Public   Static   Extern   Bool Internetsetcookie ( String Lpszurlname, String Lbszcookiename, String Lpszcookiedata );

///   <Summary>

/// Get cookie

///   </Summary>

[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)

{

// Obtain 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 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, fig 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 );

}

}

}

}

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.