Sample code for 30+ languages & platforms
PureBasic

Disconnect from a REST Server

See more REST Examples

Demonstrates Rest.Disconnect, which closes the current HTTP connection. The argument is the maximum number of milliseconds to wait for the close to complete.

Background. Connections are normally kept alive for reuse. Disconnect is used when an application wants to explicitly release the connection rather than relying on keep-alive or object destruction.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkRest.pb"

Procedure ChilkatExample()

    success.i = 0

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

    ;  Connect to the REST server.  The 3rd argument enables TLS (use 1 for HTTPS on port 443),
    ;  and the 4th enables automatic reconnection if the connection is dropped between requests.
    bTls.i = 1
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"example.com",443,bTls,bAutoReconnect)
    If success = 0
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    responseText.s = CkRest::ckFullRequestNoBody(rest,"GET","/api/status")
    If CkRest::ckLastMethodSuccess(rest) = 0
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    Debug responseText

    ;  Close the connection.  The argument is the maximum number of milliseconds to wait for the
    ;  close to complete.
    bDisconnected.i = CkRest::ckDisconnect(rest,200)
    If bDisconnected <> 1
        Debug "The disconnect did not complete within the wait time."
    EndIf

    Debug "Done."


    CkRest::ckDispose(rest)


    ProcedureReturn
EndProcedure