Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Saving and Sending Cookies with HTTP GET RequestsDownload: 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 |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.