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
|
(Visual FoxPro) Adding Cookies to an HTTP RequestDemonstrates how to add one or more cookies to an HTTP request. For Chilkat HTTP methods that use an HTTP request object, such as SynchronousRequest or PostUrlEncoded, cookies are added by calling the AddHeader method on the request object. For Chilkat HTTP methods that do not use an HTTP request object, such as QuickGetStr, cookies are added by calling AddQuickHeader. LOCAL loHttp LOCAL lnSuccess LOCAL loRequest LOCAL loResponse LOCAL lcDomain LOCAL lnPort LOCAL lnSsl LOCAL lcHtml loHttp = CreateObject('Chilkat.Http') * Any string unlocks the component for the 1st 30-days. lnSuccess = loHttp.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN ? loHttp.LastErrorText QUIT ENDIF * The Cookie header field has this format: * Cookie: name1=value1 [; name2=value2] ... * Build an HTTP POST request: loRequest = CreateObject('Chilkat.HttpRequest') loRequest.SetFromUrl("http://www.chilkatsoft.com/echoPost.asp") loRequest.HttpVerb = "POST" loRequest.AddParam("param1","value1") loRequest.AddParam("param2","value2") * To add cookies to any HTTP request sent by a Chilkat HTTP method * that uses an HTTP request object, add the cookies to the * request object by calling AddHeader. * Add two cookies: loRequest.AddHeader("Cookie",[user="mary"; city="Chicago"]) * Send the HTTP POST. * (The cookies are sent as part of the HTTP header.) lcDomain = "www.chilkatsoft.com" lnPort = 80 lnSsl = 0 loResponse = loHttp.SynchronousRequest(lcDomain,lnPort,lnSsl,loRequest) IF (loResponse = NULL ) THEN ? loHttp.LastErrorText QUIT ENDIF * Display the HTML body of the response. IF (loResponse.StatusCode = 200) THEN * Show the last HTTP request header sent, which should include * our cookies... ? loHttp.LastHeader ELSE ? "HTTP Response Status = " + loResponse.StatusCode ENDIF RELEASE loResponse ? "---------------------" * Some Chilkat HTTP methods do not use an HTTP request object. * For these methods, such as for QuickGetStr, cookies (or any HTTP request header) * are added by calling AddQuickHeader. loHttp.AddQuickHeader("Cookie",[user="mary"; city="Chicago"]) lcHtml = loHttp.QuickGetStr("http://www.w3.org/") IF (lcHtml = NULL ) THEN ? loHttp.LastErrorText ELSE * Show the last HTTP request header sent, which should include * our cookies... ? loHttp.LastHeader ENDIF |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser