C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C# Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

Saving and Sending Cookies with HTTP GET Requests

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 1.0 / 1.1 Framework

This C# example shows how to automatically save cookies to an XML filestore and automatically add cookies from the filestore to all GET requests.

Chilkat.Http http = new Chilkat.Http();
bool unlocked = http.UnlockComponent("Any string begins 30-day trial");
if (!unlocked)
{
    MessageBox.Show("Failed to unlock HTTP component");
    return;
}

// Turn off caching
http.UpdateCache = false;   // Do not save pages to cache
http.FetchFromCache = false;	// Do not fetch pages from cache

// Tell the HTTP component where to save cookies.
http.CookieDir = "c:\\Cookies\\";
http.SaveCookies = true;
// Tell the HTTP component to automatically add matching cookies to QuickGet and QuickGetStr requests.
http.SendCookies = true;

// The first time we get this page (www.thestreet.com) no cookies are sent.
// However, you will notice that an XML file named "thestreet_com.xml" has been created.
// It will contains something like this:
/*
<?xml version="1.0" encoding="utf-8" ?>

<cookies>
<cookie key=".thestreet.com,/" v="0" expire="Tue, 01-Jan-2035 00:00:00 GMT">
    <FV>OID-|PID-|MID-|PUC-|DATE-42A6145B</FV>
    <BRIS>45.03.DD.BE|42A6145B0F0A</BRIS>
    <RGIS>-1118180443,69.3.221.190,C0A81A7F,71B0489916C9-0-1118180443-</RGIS>
</cookie>
</cookies>
*/
// Chilkat HTTP stores cookies in one file per domain.
// The format of the cookie file is XML making it easy for other applications
// to use if necessary.
string htmlPage = http.QuickGetStr("http://www.thestreet.com/");

if (htmlPage.Length == 0)
{
    // Failed.
    MessageBox.Show(http.LastErrorText);
    return;
}

// Get the same page again.
// This time, the cookies will be automatically added to the HTTP request header.
// If Set-Cookie headers are included in the HTTP response, the cookie file
// is automatically updated.
string htmlPage2 = http.QuickGetStr("http://www.thestreet.com/");
if (htmlPage.Length == 0)
{
    // Failed.
    MessageBox.Show(http.LastErrorText);
    return;
}

MessageBox.Show("DONE!");

Important: The download for this example does not contain the ChilkatDotNet2.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following the instructions at
http://www.example-code.com/csharp/step2.asp

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Email Component · XML Parser