Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

C Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(C) 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.

This example shows how to compose an HTTP POST that is equivalent to what a browser would sent when a user clicks on a form submit button. Note: If client-side Javascript is utilized to compute values that are sent as credential, then Chilkat cannot be used to duplicate it.

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.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    HCkHttpRequest req;
    HCkHttpResponse resp;
    const char *strHtml;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttp_Create();

    // Let's begin by building an HTTP request to mimic the form.  
    // We must add the parameters, and set the path.
    req = CkHttpRequest_Create();
    CkHttpRequest_AddParam(req,"username","mylogin");
    CkHttpRequest_AddParam(req,"password","mypassword");
    CkHttpRequest_AddParam(req,"redirectto","/web/demo.nsf/pgWelcome?Open");

    // The path part of the POST URL is obtained from the "action" attribute of the HTML form tag.
    CkHttpRequest_putPath(req,"/auth.nsf?Login");

    CkHttpRequest_putHttpVerb(req,"POST");
    CkHttp_putFollowRedirects(http,TRUE);

    // Collect cookies in-memory and re-send in subsequent HTTP requests, including any redirects.
    CkHttp_putSendCookies(http,TRUE);
    CkHttp_putSaveCookies(http,TRUE);
    CkHttp_putCookieDir(http,"memory");

    resp = CkHttp_SynchronousRequest(http,"www.something123.com",443,TRUE,req);
    if (CkHttp_getLastMethodSuccess(http) != TRUE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        return;
    }

    // The HTTP response object can be examined.
    // To get the HTML of the response, examine the BodyStr property (assuming the POST returns HTML)
    strHtml = CkHttpResponse_bodyStr(resp);

    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkHttpRequest_Dispose(req);

    }

 

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