Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3/4 Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(Classic ASP) HTTP Form Authentication
The authentication scheme used by any given web site can vary based on its implementation. Some ways of authenticating are to send the login and password in the HTTP request header. A site that uses "Basic", "NTLM", or "Digest" authentication uses this scheme. Other sites present a web page containing an HTML form with input elements, where a user must interactively type his username and password and submit. This sends a POST to the web server with the login credentials. Form-based authentication should always occur using a secure TLS connection, otherwise the login credentials are exposed for all to see.
Suppose you have an HTML form as follows (I've eliminated all HTML tags within the form except for the input tags).
<form method="post" action="/auth.nsf?Login"> <input type="text" size="20" maxlength="256" name="username" id="user-id"> <input type="password" size="20" maxlength="256" name="password" id="pw-id"> <input type="hidden" name="redirectto" value="/web/demo.nsf/pgWelcome?Open"> <input type="submit" value="Log In"> </form>
Imagine the web site is at https://www.something123.com. The path in the "action" attribute of the form tag is the path part of the URL. Therefore, we will POST to https://www.something123.com/auth.nsf?Login
Our HTTP request will contain the following parameters: "username", "password", "redirectto", and optionally "submit". However, it is typically not necessary to add the value of the submit button input field itself. The names of the parameters are found in the "name" attribute of each input field within the HTML form. The value of a hidden input field is in the "value" attribute of the input field.
Note: This is an arbitrary example. A web site can implement forms authentication in any way it sees fit, with any number of form inputs using any names desired. There is no "standard". Every web site can and will implement it differently.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% ' This example requires the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. set http = Server.CreateObject("Chilkat_9_5_0.Http") ' Let's begin by building an HTTP request to mimic the form. ' We must add the parameters, and set the path. set req = Server.CreateObject("Chilkat_9_5_0.HttpRequest") req.AddParam "username","mylogin" req.AddParam "password","mypassword" req.AddParam "redirectto","/web/demo.nsf/pgWelcome?Open" ' The path part of the POST URL is obtained from the "action" attribute of the HTML form tag. req.Path = "/auth.nsf?Login" req.HttpVerb = "POST" http.FollowRedirects = 1 ' Collect cookies in-memory and re-send in subsequent HTTP requests, including any redirects. http.SendCookies = 1 http.SaveCookies = 1 http.CookieDir = "memory" ' resp is a Chilkat_9_5_0.HttpResponse Set resp = http.SynchronousRequest("www.something123.com",443,1,req) If (http.LastMethodSuccess <> 1) Then Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>" Response.End End If ' The HTTP response object can be examined. ' To get the HTML of the response, examine the BodyStr property (assuming the POST returns HTML) strHtml = resp.BodyStr %> </body> </html>
© 2000-2019 Chilkat Software, Inc. All Rights Reserved.