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

DataFlex 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
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

 

 

 

(DataFlex) HTTP multipart-mixed POST (for a UPS Package Level Detail PLD Request)

Important: This example requires Chilkat v9.5.0.59 or greater.

Demonstrates how to create a POST for a UPS Package Level Detail PLD Request. The request must be a multipart-mixed request having two sub-parts. The first is a application/x-www-form-urlencoded with name=value URL encoded pairs. The second is a application/x-ups-binary containing a UPS PLD request.

The HTTP request created by this example looks like this:

POST /hapld/tos/kdwhapltos HTTP/1.1
Content-Type: multipart/mixed; boundary=------------050801040202040701030308
Host: domain
Content-Length: 658

--------------050801040202040701030308
Content-type: application/x-www-form-urlencoded
Content-length: 134

AppVersion=1.0&AcceptUPSLicenseAgreement=YES&VersionNumber=V4R1&UserId=myUser&Password=myPassword&ResponseType=application/x-ups-pld

--------------050801040202040701030308
Content-type: application/x-ups-binary
Content-length: 721

020094 2014041500000594196532600 000000001*AAV0Y203 DE 5941965326000001*BA1ZV0Y2036650001829 00001+0000000000000012 +0000000000000000KGS07COL10 3CMEUR000001*CA18TC239 AOK Bahnhofstr. Dresden 01099 DE *EAEVS+000000000000104200EUR*PA1ZV0Y2036650001829 02+0000012 +0000000+00000000+00000000+00000000*SA000005

--------------050801040202040701030308--

The HTTP response (if successful) is multipart MIME as shown below. This example will extract the response content using the Chilkat MIME API.
Content-type: text/html
Content-length: 138

<HTML>
<HEAD>
<TITLE>UPS Internet Software</TITLE>
</HEAD>
<BODY>
<P>UPS Internet Software, Copyright UPS 1998</P>
</BODY>
</HTML>

--BOUNDARY
Content-type: application/x-ups-psmpld
Content-length: 104

UPSOnLine%1.0%0000%0000Successful completion - No errors found.                                    

--BOUNDARY
Content-type: application/x-ups-pld
Content-length: 800

000200000787300000640 KDGPLCR1                   United Parcel Service                      09/06/16  Page:1                    Test PLD Control Report                     05:44 PM                                                                                  ------------------------------------------------------------------------------- Pickup Date:20030813 Sequence#:000005900000002 #of Segments:000000000000000005                                                                                                                                                                  Shipper#:0TEST0     Book/Page#:5900000002 Shipments:000001 Packages:0000000001 10000012900000000Successful completion - No errors found.                                        
!!! Test Upload !!!
File Uploaded: n/a

--BOUNDARY--

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Handle hoParamEncoder
    String sUrlEncodedParams
    Handle hoSbParams
    String sPld
    Handle hoHttp
    Variant vResp
    Handle hoResp
    Handle hoMime
    Variant vPart0
    Handle hoPart0
    Variant vPart1
    Handle hoPart1
    Variant vPart2
    Handle hoPart2
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End

    // The ContentType, HttpVerb, and Path properties should
    // always be explicitly set.
    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/hapld/tos/kdwhapltos"
    Set ComContentType Of hoReq To "multipart/mixed"

    // The 1st body of the multipart/mixed HTTP request will have a content-type of application/x-www-form-urlencoded
    // It contains URL encoded parameters.
    // We'll use a temporary HTTP request object solely for the purpose of generating our URL encoded parameter string.
    Get Create (RefClass(cComChilkatHttpRequest)) To hoParamEncoder
    If (Not(IsComObjectCreated(hoParamEncoder))) Begin
        Send CreateComObject of hoParamEncoder
    End
    Send ComAddParam To hoParamEncoder "AppVersion" "1.0"
    Send ComAddParam To hoParamEncoder "AcceptUPSLicenseAgreement" "YES"
    Send ComAddParam To hoParamEncoder "VersionNumber" "V4R1"
    Send ComAddParam To hoParamEncoder "UserId" "UPS_USERID"
    Send ComAddParam To hoParamEncoder "Password" "UPS_PASSWORD"
    Get ComGetUrlEncodedParams Of hoParamEncoder To sUrlEncodedParams

    // The UPS server wants all params to be URL encoded except for the ResponseType param.
    // Therefore, we'll add ResponseType unencoded at the end, like this:
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbParams
    If (Not(IsComObjectCreated(hoSbParams))) Begin
        Send CreateComObject of hoSbParams
    End
    Get ComAppend Of hoSbParams sUrlEncodedParams To iSuccess
    Get ComAppend Of hoSbParams "&ResponseType=application/x-ups-pld" To iSuccess
    // Also, it is very important to include a CRLF at the end.  (This is to satisfy undocumented details
    // required by the UPS PLD server.)
    Get ComAppend Of hoSbParams (character(13)) + (character(10)) To iSuccess

    // Add the params as the 1st sub-part of the multipart/mixed request
    Get ComGetAsString Of hoSbParams To sTemp1
    Get ComAddStringForUpload2 Of hoReq "" "" sTemp1 "" "application/x-www-form-urlencoded" To iSuccess

    // Now for the 2nd part (using some junk data found on the developerkitcommunity.ups.com site.
    // Notice the CRLF at the end of the string.  This is important.
    Move "020094                                  2003081300000590000000200   000000001*AA0TEST0    DE                5900000002000001*BA1Z0TEST06800000018                 00001+0000000000000010 +0000000000000000KGS11PRE10                                   3CMEUR000001*CA18                                   United Parcel Service              Goerlitzer Str 1                                                                                         Neuss                              41460    DE                                                        *PA1Z0TEST06800000018                 02+0000010                                                                                      +0000000+00000000+00000000+00000000*SA000004" + (character(13)) + (character(10)) To sPld

    Get ComAddStringForUpload2 Of hoReq "" "" sPld "" "application/x-ups-binary" To iSuccess

    // The UPS PLD server requires Content-Length headers within the MIME sub-parts of the request.
    // A new feature of Chilkat v9.5.0.59 is if a Content-Length sub-header is added (with an arbitrary value, such as 0),
    // then Chilkat will compute the actual sub-part size and replace the value when the request is sent.
    Get ComAddSubHeader Of hoReq 0 "Content-Length" "0" To iSuccess
    Get ComAddSubHeader Of hoReq 1 "Content-Length" "0" To iSuccess

    // A few important comments about the HTTP request that is generated:
    // 
    // 1) Chilkat automatically generates a random boundary string.   In 99.999% of cases, this should 
    //    be sufficient.
    // 2) The top-level Content-Length header is automatically generated based on the actual length of the MIME message
    //    that follows the intial (topmost) MIME header.
    // 3) The HOST header will automatically get filled in with the actual domain when SynchronousRequest
    //    method is called.

    // Now send the request...
    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // If desired (for debugging), provide a flie path for a session log.
    // The session log can be sent to support@chilkatsoft.com if the PLD request fails.
    Set ComSessionLogFilename Of hoHttp To "c:/aaworkarea/ups_pld/sessionLog.txt"

    // Send the PLD request over TLS..
    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "www.pld-certify.ups.com" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Load the response MIME.
    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End
    Get ComFullMime Of hoResp To sTemp1
    Get ComLoadMime Of hoMime sTemp1 To iSuccess

    // If it does not have 3 sub-parts, then something is amiss...
    Get ComNumParts Of hoMime To iTemp1
    If (iTemp1 <> 3) Begin
        Showln "Unexpected number of MIME parts."
        Get ComFullMime Of hoResp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Examine each response part.
    Get ComGetPart Of hoMime 0 To vPart0
    If (IsComObject(vPart0)) Begin
        Get Create (RefClass(cComChilkatMime)) To hoPart0
        Set pvComObject Of hoPart0 To vPart0
    End
    Showln "---- text/html part ----"
    Get ComGetBodyDecoded Of hoPart0 To sTemp1
    Showln sTemp1

    Get ComGetPart Of hoMime 1 To vPart1
    If (IsComObject(vPart1)) Begin
        Get Create (RefClass(cComChilkatMime)) To hoPart1
        Set pvComObject Of hoPart1 To vPart1
    End
    Showln "---- application/x-ups-psmpld part ----"
    Get ComGetBodyDecoded Of hoPart1 To sTemp1
    Showln sTemp1

    Get ComGetPart Of hoMime 2 To vPart2
    If (IsComObject(vPart2)) Begin
        Get Create (RefClass(cComChilkatMime)) To hoPart2
        Set pvComObject Of hoPart2 To vPart2
    End
    Showln "---- application/x-ups-pld part ----"
    Get ComGetBodyDecoded Of hoPart2 To sTemp1
    Showln sTemp1

    Send Destroy of hoPart0
    Send Destroy of hoPart1
    Send Destroy of hoPart2
    Send Destroy of hoResp


End_Procedure

 

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