Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Get Response Header for Method that does not Return HttpResponse ObjectDemonstrates how to get the response header and individual response header fields for a method that does not return an HTTP response object. (If a method returns an HHTTP response object, then the response header information should be obtained from the response object.)
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example requires the Chilkat 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 DECLARE @strHtml nvarchar(4000) EXEC sp_OAMethod @http, 'QuickGetStr', @strHtml OUT, 'https://www.duckduckgo.com/' EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http RETURN END EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT PRINT @sTmp0 -- Here's a sample HTTP response header: -- Server: nginx -- Date: Wed, 30 Sep 2020 13:13:02 GMT -- Content-Type: text/html; charset=UTF-8 -- Transfer-Encoding: chunked -- Connection: keep-alive -- Vary: Accept-Encoding -- ETag: W/"5f7371f4-1683" -- Strict-Transport-Security: max-age=31536000 -- X-Frame-Options: SAMEORIGIN -- Content-Security-Policy: default-src https: blob: data: 'unsafe-inline' 'unsafe-eval'; frame-ancestors 'self' -- X-XSS-Protection: 1;mode=block -- X-Content-Type-Options: nosniff -- Referrer-Policy: origin -- Expect-CT: max-age=0 -- Expires: Wed, 30 Sep 2020 13:13:01 GMT -- Cache-Control: no-cache -- Content-Encoding: gzip -- We can load it into a Chilkat MIME object to get header field values: DECLARE @mime int -- Use "Chilkat_9_5_0.Mime" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT DECLARE @success int EXEC sp_OAGetProperty @http, 'LastResponseHeader', @sTmp0 OUT EXEC sp_OAMethod @mime, 'LoadMime', @success OUT, @sTmp0 IF @success = 0 BEGIN EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @mime RETURN END -- Get MIME header field values using Chilkat MIME... PRINT '----' EXEC sp_OAMethod @mime, 'GetHeaderField', @sTmp0 OUT, 'ETag' PRINT 'ETag: ' + @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @mime END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.