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
Socket
Spider
String
Tar
Upload
XML
XMP
Zip

Byte Array
RSS
Atom
Self-Extractor

HTTPS Form Login

Using the del.icio.us site, demonstrates how to programmatically login via a form.

Download Chilkat HTTP ActiveX

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

    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

    --  Cookies may be persisted to a directory in the filesystem,
    --  or alternatively cached in memory by using the "memory"
    --  keyword:
    EXEC sp_OASetProperty @http, 'CookieDir', 'memory'
    --  Accumulated cookies are sent with each GET/POST:
    EXEC sp_OASetProperty @http, 'SaveCookies', 1
    --  Cookies received in HTTP responses are to be saved:
    EXEC sp_OASetProperty @http, 'SendCookies', 1

    --  Get the page with the login form.  We're only doing this
    --  just in case there are cookies that need to be cached
    --  and re-sent in the next step:
    DECLARE @html nvarchar(4000)

    EXEC sp_OAMethod @http, 'QuickGetStr', @html OUT, 'https://secure.del.icio.us/login'
    EXEC sp_OAGetProperty @http, 'LastStatus', @sTmp0 OUT
    IF @sTmp0 <> 200
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        RETURN
      END

    --  Examining the "Page Info" in FireFox reveals a form with
    --  a target of https://secure.del.icio.us/login with
    --  fields of "user_name", "password", and "login".  The "login"
    --  field is nothing more than the submit button and holds
    --  the value "log in".

    --  Build an HTTP POST Request:
    EXEC sp_OAMethod @req, 'UsePost', NULL
    EXEC sp_OASetProperty @req, 'Path', '/login'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'user_name', 'chilkatsoft'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'password', '****'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'login', 'log in'

    --  Send the HTTP POST and get the response.  Note: This is a blocking call.
    --  The method does not return until the full HTTP response is received.
    DECLARE @domain nvarchar(4000)

    DECLARE @port int

    DECLARE @ssl int

    SELECT @domain = 'secure.del.icio.us'
    SELECT @port = 443
    SELECT @ssl = 1
    DECLARE @resp int

    EXEC sp_OAMethod @http, 'SynchronousRequest', @resp OUT, @domain, @port, @ssl, @req
    IF @resp Is NULL 
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT

        PRINT @sTmp0
      END
    ELSE
      BEGIN
        DECLARE @responseStatus int

        EXEC sp_OAGetProperty @resp, 'StatusCode', @responseStatus OUT

        IF @responseStatus = 302
          BEGIN

            --  We have a redirect.  Follow it...
            --  Note: the FollowRedirects property causes
            --  301/302 responses to GET requests to be
            --  automatically followed.
            EXEC sp_OASetProperty @http, 'FollowRedirects', 1
            EXEC sp_OAMethod @resp, 'GetHeaderField', @sTmp0 OUT, 'Location'            EXEC sp_OAMethod @http, 'QuickGetStr', @html OUT, @sTmp0
            EXEC sp_OAGetProperty @http, 'LastStatus', @sTmp0 OUT
            IF @sTmp0 <> 200
              BEGIN
                EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
                PRINT @sTmp0
                RETURN
              END

          END
        ELSE
          BEGIN
            EXEC sp_OAGetProperty @resp, 'BodyStr', @html OUT

          END


        PRINT STR(@responseStatus)

        --  Display the HTML source of the page returned.

        PRINT @html

      END
END
GO

 

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

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