SQL Server Stored Procedure Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

SQL Server
Stored Procedure Examples

Quick Start
Encryption
File Access
IMAP
POP3
SMTP
Email Object
FTP
HTML-to-XML
HTTP
MHT
MIME
RSA Encryption
Diffie-Hellman
DSA
Socket
Spider
String
Tar
Upload
XML
XMP
Zip

Byte Array
RSS
Atom
Self-Extractor

Adding Cookies to an HTTP GET Request

Example showing how to add one or more cookies to an HTTP GET request.

Download Chilkat HTTP ActiveX

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  Any string unlocks the component for the 1st 30-days.
    EXEC sp_OAMethod @http, 'UnlockComponent', @success OUT, 'Anything for 30-day trial'
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  The Cookie header field has this format:
    --  Cookie: name1=value1 [; name2=value2] ...

    --  Build an HTTP GET request:
    DECLARE @request int
    EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @request OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @request, 'SetFromUrl', NULL, 'http://www.example-code.com/'
    EXEC sp_OAMethod @request, 'UseGet', NULL

    --  Add two cookies:
    EXEC sp_OAMethod @request, 'AddHeader', NULL, 'Cookie', 'user="mary"; city="Chicago"'

    --  Send the HTTP GET.  The cookies are sent as part of the HTTP header.
    DECLARE @response int

    DECLARE @domain nvarchar(4000)

    SELECT @domain = 'www.example-code.com'
    DECLARE @port int

    SELECT @port = 80
    DECLARE @ssl int

    SELECT @ssl = 0
    EXEC sp_OAMethod @http, 'SynchronousRequest', @response OUT, @domain, @port, @ssl, @request
    IF @response Is NULL 
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  Display the HTML body of the response.
    EXEC sp_OAGetProperty @response, 'StatusCode', @sTmp0 OUT
    IF @sTmp0 = 200
      BEGIN
        EXEC sp_OAGetProperty @response, 'BodyStr', @sTmp0 OUT

        PRINT @sTmp0
      END
    ELSE
      BEGIN

        EXEC sp_OAGetProperty @response, 'StatusCode', @iTmp0 OUT

        PRINT 'HTTP Response Status = ' + @iTmp0
      END


END
GO

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2007 Chilkat Software, Inc. All Rights Reserved.