Sample code for 30+ languages & platforms
DataFlex

HTTP HEAD Request

See more HTTP Examples

Sends an HTTP HEAD request and gets the response.

Note: The response to an HTTP HEAD request is always just the response header. The reponse body is always 0 length (thus the reason it's called a "HEAD" request..)

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vResp
    Handle hoResp
    Integer iNumHeaderFields
    Integer i
    String sTemp1
    String sTemp2
    Integer iTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // If the URL uses "https://", then the connection will be TLS.
    // Otherwise it will be TCP.

    // A failure is when we don't get any response.  It could be a timeout, an inability to connect, etc.
    // For example, a "404 Not Found" response is still a response, and thus deemed success in terms of the API..

    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoResp to vResp
    Get ComHttpNoBody Of hoHttp "HEAD" "https://example-code.com/" vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Examine the response.
    Get ComStatusCode Of hoResp To iTemp1
    Showln "Status Code = " iTemp1
    Get ComStatusLine Of hoResp To sTemp1
    Showln "Status Line = " sTemp1
    Get ComStatusText Of hoResp To sTemp1
    Showln "Status Text = " sTemp1
    Showln "Full Response Header:"
    Get ComHeader Of hoResp To sTemp1
    Showln sTemp1
    Showln "----"
    Get ComNumHeaderFields Of hoResp To iNumHeaderFields
    Showln "Num Header Fields: " iNumHeaderFields

    For i From 0 To (iNumHeaderFields - 1)
        Get ComGetHeaderName Of hoResp i To sTemp1
        Get ComGetHeaderValue Of hoResp i To sTemp2
        Showln sTemp1 ": " sTemp2
    Loop



End_Procedure