Sample code for 30+ languages & platforms
DataFlex

HTTPS Upload File to Web Server

See more HTTP Examples

Uploads a file to a web server using HTTPS.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vReq
    Handle hoReq
    Handle hoHttp
    Boolean iUseSslTls
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    // 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.
    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/receiveMyUpload.aspx"
    Set ComContentType Of hoReq To "multipart/form-data"

    Get ComAddStringForUpload Of hoReq "fileA" "fileA.txt" "This is the contents of file A" "utf-8" To iSuccess
    Get ComAddFileForUpload Of hoReq "starfish.jpg" "qa_data/jpg/starfish.jpg" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoReq To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // ----------------------------------------------------------------------------
    // 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.
    Move True To iUseSslTls
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoReq to vReq
    Get pvComObject of hoResp to vResp
    Get ComHttpSReq Of hoHttp "www.example.com" 443 iUseSslTls vReq vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln "response status code = " iTemp1
    Showln "response body:"
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1


End_Procedure