SQL Server
SQL Server
Inspect HTTP Request Header
Demonstrates theLastHeader property.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @url nvarchar(4000)
SELECT @url = 'https://chilkatsoft.com/echo_request_body.asp'
DECLARE @json nvarchar(4000)
SELECT @json = '{"greeting":"Hello World"}'
-- Send a POST with the JSON in the HTTP request body.
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
EXEC sp_OAMethod @http, 'HttpStr', @success OUT, 'POST', @url, @json, 'utf-8', 'application/json', @resp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
RETURN
END
-- Examine the HTTP request header we just sent.
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
-- Output:
-- POST /echo_request_body.asp HTTP/1.1
-- Host: chilkatsoft.com
-- Accept: */*
-- Accept-Encoding: gzip
-- Content-Type: application/json
-- Content-Length: 26
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
END
GO