Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
(SQL Server) HTTP Authentication (Basic, NTLM, Digest, Negotiate/Kerberos)Demonstrates how to use HTTP authentication. Authentication can be added to any method that sends an HTTP request to the server, such as SynchronousRequest, QuickGetStr, PostXml, etc. To add authentication, simply set the Login and Password properties. By default, Chilkat will use basic HTTP authentication, which sends the login/password clear-text over the connection. This is bad if SSL/TLS (i.e. HTTPS) is not used. However, if the connection is secure, there should be nothing wrong with using basic authentication. Chilkat supports more secure authentication types as well, including Digest, NTLM, and Negotiate (which dynamically chooses between NTLM and Kerberos). To use Digest authentication, simply set the DigestAuth property = 1. To use NTLM authentication, set the NtlmAuth property = 1. Likewise, to use Negotiate authentication, set the NegotiateAuth property = 1. Important: Negotiate authentication is only supported for the Chilkat implementations that run on the Windows platform. This is because it is implemented internally using Microsoft's SSPI API. NTLM authentication however, is available for all supported operating systems because Chilkat implements NTLM directlly (i.e. does not use Microsoft SSPI for the underlying implementation.) 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 -- Set the Login and Password properties for authentication. EXEC sp_OASetProperty @http, 'Login', 'chilkat' EXEC sp_OASetProperty @http, 'Password', 'myPassword' DECLARE @html nvarchar(4000) EXEC sp_OAMethod @http, 'QuickGetStr', @html OUT, 'http://localhost/xyz.html' -- Note: IF @html Is NULL BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Examine the HTTP status code returned. -- A status code of 401 is typically returned for "access denied" -- if no login/password is provided, or if the credentials (login/password) -- are incorrect. EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT PRINT 'HTTP status code for Basic authentication: ' + @iTmp0 -- Examine the HTML returned for the URL: PRINT @html DECLARE @http2 int EXEC @hr = sp_OACreate 'Chilkat.Http', @http2 OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- To use NTLM authentication, set the -- NtlmAuth property = 1 EXEC sp_OASetProperty @http2, 'NtlmAuth', 1 -- The session log can be captured to a file by -- setting the SessionLogFilename property: EXEC sp_OASetProperty @http2, 'SessionLogFilename', 'ntlmAuthLog.txt' -- Examination of the HTTP session log will show the NTLM -- back-and-forth exchange between the client and server. -- This call will now use NTLM authentication (assuming it -- is supported by the web server). EXEC sp_OAMethod @http2, 'QuickGetStr', @html OUT, 'http://localhost/xyz.html' -- Note: IF @html Is NULL BEGIN EXEC sp_OAGetProperty @http2, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OAGetProperty @http2, 'LastStatus', @iTmp0 OUT PRINT 'HTTP status code for NTLM authentication: ' + @iTmp0 DECLARE @http3 int EXEC @hr = sp_OACreate 'Chilkat.Http', @http3 OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- To use Digest Authentication, set the DigestAuth property = 1 -- Also, no more than one of the authentication type properties -- (NtlmAuth, DigestAuth, and NegotiateAuth) should be set -- to 1. EXEC sp_OASetProperty @http3, 'DigestAuth', 1 EXEC sp_OASetProperty @http3, 'SessionLogFilename', 'digestAuthLog.txt' -- This call will now use Digest authentication (assuming it -- is supported by the web server). EXEC sp_OAMethod @http3, 'QuickGetStr', @html OUT, 'http://localhost/xyz.html' -- Note: IF @html Is NULL BEGIN EXEC sp_OAGetProperty @http3, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OAGetProperty @http3, 'LastStatus', @iTmp0 OUT PRINT 'HTTP status code for Digest authentication: ' + @iTmp0 END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.