PureBasic
PureBasic
HTTP Response Inspection
See more HTTP Examples
Demonstrates how to inspect the HTTP response, including the status code, status text, and response headers, for Chilkat methods that don't use anHttpResponse object.
Chilkat PureBasic Downloads
IncludeFile "CkMime.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Returns the contents of the response body.
jsonText.s = CkHttp::ckQuickGetStr(http,"https://chilkatsoft.com/helloWorld.json")
; Examine the response status code.
Debug "response status code: " + Str(CkHttp::ckLastStatus(http))
; Examine the response status text
Debug "response status text: " + CkHttp::ckLastStatusText(http)
; Examine the full response header.
Debug "response header:"
Debug CkHttp::ckLastResponseHeader(http)
Debug "----"
; Examine the response content-type
Debug "LastContentType = " + CkHttp::ckLastContentType(http)
; Examine the response last-mod date
Debug "LastModDate = " + CkHttp::ckLastModDate(http)
; Load the response header into a Chilkat MIME object to access its fields individually.
mime.i = CkMime::ckCreate()
If mime.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkMime::ckLoadMime(mime,CkHttp::ckLastResponseHeader(http))
numHeaders.i = CkMime::ckNumHeaderFields(mime)
i.i = 0
Debug "---- MIME Headers ----"
While i < numHeaders
Debug "name: " + CkMime::ckGetHeaderFieldName(mime,i)
Debug "value: " + CkMime::ckGetHeaderFieldValue(mime,i)
i = i + 1
Wend
Debug "----"
; Get a header field value by name:
Debug "ETag: " + CkMime::ckGetHeaderField(mime,"ETag")
; Output:
; response status code: 200
; response status text: OK
; response header:
; Content-Type: application/json
; Last-Modified: Sun, 20 Aug 2023 11:36:27 GMT
; Accept-Ranges: bytes
; ETag: "34c27f8e5ad3d91:0"
; Server: Microsoft-IIS/10.0
; X-Powered-By: ASP.NET
; Date: Sat, 30 Aug 2025 14:38:13 GMT
; Content-Length: 22
; ----
; LastContentType = application/json
; LastModDate = 2023-08-20
; ---- MIME Headers ----
; name: Content-Type
; value: application/json
; name: Last-Modified
; value: Sun, 20 Aug 2023 11:36:27 GMT
; name: Accept-Ranges
; value: bytes
; name: ETag
; value: "34c27f8e5ad3d91:0"
; name: Server
; value: Microsoft-IIS/10.0
; name: X-Powered-By
; value: ASP.NET
; name: Date
; value: Sat, 30 Aug 2025 14:38:13 GMT
; name: Content-Length
; value: 22
; ----
; ETag: "34c27f8e5ad3d91:0"
CkHttp::ckDispose(http)
CkMime::ckDispose(mime)
ProcedureReturn
EndProcedure