Sample code for 30+ languages & platforms
Xbase++

Examine HTTP Response Status Code and Text

See more REST Examples

Demonstrates how to examine the HTTP response status code and text when using the REST object.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL cResponseText

nSuccess := 0

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

oRest := CreateObject("Chilkat.Rest")

//  We're going to check https://authenticationtest.com/HTTPAuth/
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("authenticationtest.com", nPort, nBTls, nBAutoReconnect)
IF (nSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

//  Send a GET request
cResponseText := oRest:FullRequestNoBody("GET", "/HTTPAuth/")
IF (oRest:LastMethodSuccess != 1)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

//  The start line of an HTTP response, called the status line, contains the following information:
//  
//      The protocol version, usually HTTP/1.1.
//      A status code, indicating success or failure of the request. Common status codes are 200, 404, or 302
//      A status text. A brief, purely informational, textual description of the status code to help a human understand the HTTP message.
//  
//  A typical status line looks like: HTTP/1.1 404 Not Found.

//  The ResponseStatusCode property contains the integer response code:
? "Response status code = " + Str(oRest:ResponseStatusCode)

//  The ResponseStatusText property contains the text (if any) that follows the status code on the status line.
? "Response status text = " + oRest:ResponseStatusText

//  In this case, the sample output is:
//  
//  Response status code = 401
//  Response status text = Unauthorized

oRest:destroy()