Xbase++
Xbase++
HTTPS Upload File to Web Server
See more HTTP Examples
Uploads a file to a web server using HTTPS.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oReq
LOCAL oHttp
LOCAL nUseSslTls
LOCAL oResp
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The ContentType, HttpVerb, and Path properties should
// always be explicitly set.
oReq := CreateObject("Chilkat.HttpRequest")
oReq:HttpVerb := "POST"
oReq:Path := "/receiveMyUpload.aspx"
oReq:ContentType := "multipart/form-data"
oReq:AddStringForUpload("fileA", "fileA.txt", "This is the contents of file A", "utf-8")
nSuccess := oReq:AddFileForUpload("starfish.jpg", "qa_data/jpg/starfish.jpg")
IF (nSuccess == 0)
? oReq:LastErrorText
oReq:destroy()
RETURN
ENDIF
oHttp := CreateObject("Chilkat.Http")
// ----------------------------------------------------------------------------
// IMPORTANT:
// HTTP uploads require a counterpart implementation on the server, written in any desired language
// such as C#, Classic ASP, PHP, etc., which consumes the upload being sent.
// See: ASP.NET Receive Upload
// ----------------------------------------------------------------------------
// Do the upload.
nUseSslTls := 1
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpSReq("www.example.com", 443, nUseSslTls, oReq, oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oReq:destroy()
oHttp:destroy()
oResp:destroy()
RETURN
ENDIF
? "response status code = " + Str(oResp:StatusCode)
? "response body:"
? oResp:BodyStr
oReq:destroy()
oHttp:destroy()
oResp:destroy()