Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PowerBuilder Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PowerBuilder) HTTPS multipart/form-data POST

Demonstrates how to send a multipart/form-data POST over HTTPS (using TLS).

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Req
string ls_PathToFileOnDisk
integer li_Success
string ls_FileContents
oleobject loo_Http
oleobject loo_Resp
string ls_HtmlStr

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

// This example demonstrates how to send a multipart/form-data POST that
// looks like this:

// 	POST /cgi/XXX.pl HTTP/1.0
// 	Accept: text/html
// 	Connection: Keep-Alive
// 	User-Agent: XXX/8.0.15
// 	Content-type: multipart/form-data, boundary=XXXxyxy
// 	Content-Length: 682
// 
// 	--XXXxyxy
// 	content-disposition: form-data; name="UploadAgent"
// 
// 	InterfaceVersion1.5
// 	--XXXxyxy
// 	content-disposition: form-data; name="user"
// 
// 	XXX
// 	--XXXxyxy
// 	content-disposition: form-data; name="password"
// 
// 	XXX
// 	--XXXxyxy
// 	content-disposition: form-data; name="file"
// 
// 	XXX
// 	--XXXxyxy
// 	content-disposition: form-data; name="data_version"
// 
// 	XXX:??
// 	--XXXxyxy
// 	content-disposition: form-data; name="content2"; filename="XXX"
// 
// 	THE FILE CONTENT GOES HERE...
// 	--XXXxyxy--
// 

// First, let's build the HTTP request object
loo_Req = create oleobject
li_rc = loo_Req.ConnectToNewObject("Chilkat_9_5_0.HttpRequest")
if li_rc < 0 then
    destroy loo_Req
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Req.HttpVerb = "POST"
loo_Req.Path = "/cgi/XXX.pl"

// The boundary string is automatically generated and added by Chilkat.
// The value for the boundary string doesn't matter. (As long as it's a unique string that doesn't occur elsewhere in the request.)
loo_Req.ContentType = "multipart/form-data"

// Adding the Connection: Keep-Alive is optional.  It only makes sense if the intent is to send
// additional requests to the same domain (your-namespace-sb.accesscontrol.windows.net) within a reasonable time period.
loo_Req.AddHeader("Connection","Keep-Alive")

// --------------------------------------------------
// IMPORTANT: Never set the Content-Length header.  
// Chilkat will automatically compute the correct Content-Length and will add it.
// --------------------------------------------------

// If a specific User-Agent header field is needed, it can be added by calling AddHeader.
loo_Req.AddHeader("User-Agent","XXX/8.0.15")

// The "Accept" header, if present, tells the server what Content-Type responses will be accepted.
// In this case, we're telling the server that we'll only accept "text/html" responses, and therefore
// the server SHOULD only send a text/html response.  Technically, the Accept header is not required.
loo_Req.AddHeader("Accept","text/html")

// Add the params to the request.  Given that the Content-Type is set to "multipart/form-data", when
// Chilkat composes the request, it will put each param in it's own MIME sub-part (i.e. in it's own
// part delimited by the boundary string).
loo_Req.AddParam("UploadAgent","InterfaceVersion1.5")
loo_Req.AddParam("user","XXX")
loo_Req.AddParam("password","XXX")
loo_Req.AddParam("file","XXX")
loo_Req.AddParam("data_version","XXX")

// The last param is the contents of a file.
// If it's a file on disk, we can add it like this:
ls_PathToFileOnDisk = "c:/someDir/someFile.dat"
li_Success = loo_Req.AddFileForUpload("content2",ls_PathToFileOnDisk)
if li_Success <> 1 then
    Write-Debug loo_Req.LastErrorText
    destroy loo_Req
    return
end if

// Alternatively, if the contents of the file are in memory, perhaps in a string
// variable, the file can be added like this instead.
ls_FileContents = "This is the content of the file being uploaded."
li_Success = loo_Req.AddStringForUpload("content2","XXX",ls_FileContents,"utf-8")

// -----------------------------------------------------------
// IMPORTANT: To duplicate the HTTP request shown above, you'll want to choose 
// either AddStringForUpload or AddFileForUpload, but not both.  It's possible to upload
// any number of files by calling AddStringForUpload and/or AddFileForUpload any number
// of times, once per file to be uploaded.  This of course assumes that the receiving
// end is programmed to receive multiple files..
// ------------------------------------------------------------

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")

// The request is ready... now send it using HTTPS (which is port 443 by default).

loo_Resp = loo_Http.SynchronousRequest("www.myserver.com",443,1,loo_Req)
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Req
    destroy loo_Http
    return
end if

Write-Debug "HTTP response status: " + string(loo_Resp.StatusCode)

// In this case, the response would be HTML because our Accept header
// told the server to only return HTML.  The HTML is available on the BodyStr
// property of the response object:
ls_HtmlStr = loo_Resp.BodyStr
Write-Debug "Received:"
Write-Debug ls_HtmlStr

destroy loo_Resp


destroy loo_Req
destroy loo_Http

 

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