Sample code for 30+ languages & platforms
PureBasic

Example: Http.CloseAllConnections method

See more HTTP Examples

Demonstrates how to call the CloseAllConnections method.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"

Procedure ChilkatExample()

    success.i = 0

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

    ; Demonstrate 
    url.s = "https://finnhub.io/api/v1/quote?symbol={$symbol}&token={$api_key}"

    ; When the request is sent, the {$symbol} is replaced with "MSFT"
    ; and the {$api_key} is replaced with "1234567890ABCDEF"
    CkHttp::ckSetUrlVar(http,"symbol","MSFT")
    CkHttp::ckSetUrlVar(http,"api_key","1234567890ABCDEF")

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

    success = CkHttp::ckQuickGetSb(http,url,sbJson)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbJson)
        ProcedureReturn
    EndIf

    statusCode.i = CkHttp::ckLastStatus(http)
    Debug CkHttp::ckLastResponseHeader(http)

    ; The response header contains this:

    ; Date: Tue, 19 Aug 2025 12:18:56 GMT
    ; Content-Type: application/json; charset=utf-8
    ; Transfer-Encoding: chunked
    ; Connection: keep-alive
    ; Content-Encoding: gzip

    ; The "Connection: keep-alive" header ensures the server keeps the connection open for subsequent requests.
    ; If the server responds with a "Connection: close" header, it indicates the connection will be closed after the response. 
    ; Consequently, Chilkat will also close the connection, requiring a new one to be established for any subsequent requests to the same server.

    ; If your application uses the same HTTP object instance to send requests to a different server, a new connection will be established with that server.
    ; Existing connections remain open, with Chilkat maintaining up to 10 open connections. 
    ; If all 10 connections are in use, Chilkat will close the least recently used connection to connect to a new server.

    ; Your application can explicitly close all open connections like this:
    success = CkHttp::ckCloseAllConnections(http)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbJson)
        ProcedureReturn
    EndIf

    Debug "Success."


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbJson)


    ProcedureReturn
EndProcedure