Sample code for 30+ languages & platforms
PureBasic

Send HTTPS POST with XML Body

See more HTTP Examples

Demonstrates how to send an HTTP (or HTTPS) POST where the body of the request is XML.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    strXml.s = "<TransactionSetup xmlns=" + Chr(34) + "https://xyz.com" + Chr(34) + "><Credentials><AccountID>XXX</AccountID></Credentials></TransactionSetup>"

    ; Maybe you need other headers?
    CkHttp::ckSetRequestHeader(http,"Accept","application/xml")

    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckHttpStr(http,"POST","https://www.somewebsite.com/",strXml,"utf-8","application/xml",resp)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        ProcedureReturn
    EndIf

    ; Examine the response status code:
    Debug "response status code = " + Str(CkHttpResponse::ckStatusCode(resp))

    ; Examine the response body:
    Debug "response body: " + CkHttpResponse::ckBodyStr(resp)


    CkHttp::ckDispose(http)
    CkHttpResponse::ckDispose(resp)


    ProcedureReturn
EndProcedure