![]() |
Chilkat • HOME • Android™ • AutoIt • C • C# • C++ • Chilkat2-Python • CkPython • Classic ASP • DataFlex • Delphi DLL • Go • Java • Node.js • Objective-C • PHP Extension • Perl • PowerBuilder • PowerShell • PureBasic • Ruby • SQL Server • Swift • Tcl • Unicode C • Unicode C++ • VB.NET • VBScript • Visual Basic 6.0 • Visual FoxPro • Xojo Plugin
(SQL Server) Demonstrates how to Get Cookies Sent by the HTTP ServerThis example demonstrates how to get the cookies that have been received from the HTTP server.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- This example assumes the Chilkat HTTP API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- When the HTTP object's SaveCookies property is turned on, the cookies received from the server -- are persited to the CookieDir, which could be a directory where cookie XML files are persisted, -- or the keyword "memory" to keep an in-memory store. EXEC sp_OASetProperty @http, 'SaveCookies', 1 EXEC sp_OASetProperty @http, 'CookieDir', 'memory' -- Do a few GET's DECLARE @html nvarchar(4000) EXEC sp_OAMethod @http, 'QuickGetStr', @html OUT, 'https://www.google.com/' EXEC sp_OAMethod @http, 'QuickGetStr', @html OUT, 'https://www.amazon.com/' -- Examine the cookies received from each domain. DECLARE @googleCookies nvarchar(4000) EXEC sp_OAMethod @http, 'GetCookieXml', @googleCookies OUT, 'www.google.com' PRINT @googleCookies -- Sample output: -- <?xml version="1.0" encoding="utf-8" ?> -- <cookies> -- <cookie key=".google.com,/,NID" v="0" expire="Mon, 25-Sep-2017 04:26:57 GMT"> -- <NID>99=AjPVGwqGMP04vlJfmb2r0Zuorv43CnFNWFrIDz8IUrcF5ozTXa7DWBRUR1-_WqcXXQymVNLe9Umr84N87ynLAYzlRZ74ww9pU8f1ZK-pHL88RPcobnlsxE7Xi-XdXR1a6dCQ-5hOoHw7juRB</NID> -- </cookie> -- </cookies> -- DECLARE @amazonCookies nvarchar(4000) EXEC sp_OAMethod @http, 'GetCookieXml', @amazonCookies OUT, 'www.amazon.com' PRINT @amazonCookies -- Sample output: -- <?xml version="1.0" encoding="utf-8" ?> -- <cookies> -- <cookie key=".amazon.com,/,skin" v="0"> -- <skin>noskin</skin> -- </cookie> -- <cookie key=".amazon.com,/,session-id" v="0" expire="Tue, 01-Jan-2036 08:00:01 GMT"> -- <session-id>159-1495930-0239038</session-id> -- </cookie> -- <cookie key=".amazon.com,/,session-id-time" v="0" expire="Tue, 01-Jan-2036 08:00:01 GMT"> -- <session-id-time>2082787201l</session-id-time> -- </cookie> -- </cookies> EXEC @hr = sp_OADestroy @http END GO |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.