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

Unicode 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

 

 

 

(Unicode C++) Duplicating a Simple HTML Form Submission (POST)

This example shows how to duplicate a simple HTML form submission. The HTML to be duplicated is shown below, and may be tested in a browser by going to this URL: http://www.chilkatsoft.com/postSample.html


<html>
<body>
<form action="echoPost.asp" method="post">
<p>First name: <input name="firstname"></p>
<p>Last name: <input name="lastname"></p>
<p>Your favorite color:
<select name="color">
<option>Blue</option>
<option>Green</option>
<option>Red</option>
<option>Yellow</option>
<option>Pink</option>
</select>
</p>
<input type="hidden" name="myHiddenField1", value="Hidden Value 1">
<input type="hidden" name="myHiddenField2", value="Hidden Value 2">
<p><input type="submit" value="Send POST"></p>
</form>

</body>
</html>

By default, a browser will send a form POST as an HTTP reqeuest using a Content-Type of "application/x-www-form-urlencoded". This is because the form parameters are sent in the body of the HTTP POST using the URL encoding. Therefore, one should use the PostUrlEncoded method to duplicate the form submission.

Each "input" or "select" tag found in the HTML is a form parameter having a name and value. These are duplicated in code by calling AddParam on the HTTP Request object for each parameter.

The target URL is indicated by the "action" attribute on the "form" tag. In the HTML form shown above, it is "echoPost.asp". The URL specified in the "action" attribute may be an absolute or relative URL. In this case, it is a relative URL, and since there is no directory path, the full URL of the POST target is "http://www.chilkatsoft.com/echoPost.asp". This will be the 1st argument passed to the PostUrlEncoded method.

The raw HTTP POST sent to the web server in this example is shown below. The form parameters are located in the body of the request (i.e. under the header fields), and they are URL encoded.

POST /echoPost.asp HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: www.chilkatsoft.com
Content-Length: 87

firstname=John&lastname=Doe&myHiddenField1=Hidden+Value+1&myHiddenField2=Hidden+Value+2

Note: An HTTP file upload is a form submission having an "input" tag w/ "type=file". In this case, a browser will send the POST using a content-type of "multipart/form-data". The PostUrlEncoded method should not be called for HTTP file uploads. The SynchronousRequest would instead be called.

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 <CkHttpW.h>
#include <CkHttpRequestW.h>
#include <CkHttpResponseW.h>

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

    CkHttpW http;

    CkHttpRequestW req;

    // Add the form parameters to the HTTP request:
    req.AddParam(L"firstname",L"John");
    req.AddParam(L"lastname",L"Doe");
    req.AddParam(L"myHiddenField1",L"Hidden Value 1");
    req.AddParam(L"myHiddenField2",L"Hidden Value 2");

    // Send the HTTP POST by calling PostUrlEncoded.
    // The Content-Type used w/ the request will be application/x-www-form-urlencoded
    CkHttpResponseW *resp = http.PostUrlEncoded(L"http://www.chilkatsoft.com/echoPost.asp",req);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    // Display the Body of the HTTP resp
    // (This is the HTML that the browser would receive if it
    // had been an interactive form submission from the browser.)
    wprintf(L"%s\n",resp->bodyStr());

    delete resp;
    }

 

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