Sample code for 30+ languages & platforms
PureBasic

Transition from Http.GetHead to Http.HttpNoBody

Provides instructions for replacing deprecated GetHead method calls with HttpNoBody.

Chilkat PureBasic Downloads

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

Procedure ChilkatExample()

    success.i = 0

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

    url.s = "https://www.example.com/"

    ; ------------------------------------------------------------------------
    ; The GetHead method is deprecated:

    resp1.i = CkHttp::ckGetHead(http,url)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp1))
    CkHttpResponse::ckDispose(resp1)

    ; ------------------------------------------------------------------------
    ; Do the equivalent using HttpNoBody.
    ; Your application creates a new, empty response object which is passed 
    ; in the last argument and filled with the HTTP response upon success.

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

    success = CkHttp::ckHttpNoBody(http,"HEAD",url,resp2)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp2)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp2))


    CkHttp::ckDispose(http)
    CkHttpResponse::ckDispose(resp2)


    ProcedureReturn
EndProcedure