C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

Saving and Sending Cookies with HTTP GET Requests

Download: Chilkat .NET Assemblies

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

 

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

Email Component · XML Parser