Sample code for 30+ languages & platforms
PureBasic

Example: Http.DownloadSb method

See more HTTP Examples

Demonstrates the DownloadSb 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

    CkHttp::setCkKeepResponseBody(http, 1)

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

    success = CkHttp::ckDownloadSb(http,"https://chilkatsoft.com/testData/helloWorld.txt","utf-8",sb)

    statusCode.i = CkHttp::ckLastStatus(http)
    If success = 0
        If statusCode = 0
            ; Unable to either send the request or get the response.
            Debug CkHttp::ckLastErrorText(http)
        Else
            ; We got a response, but the status code was not in the 200s
            Debug "Response status code: " + Str(statusCode)
            ; Examine the response body.
            Debug "Response body:"
            Debug CkHttp::ckLastResponseBody(http)
        EndIf

        Debug "Download failed."

    Else
        Debug "Download success, response status = " + Str(statusCode)
        Debug CkStringBuilder::ckGetAsString(sb)
    EndIf



    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sb)


    ProcedureReturn
EndProcedure