Sample code for 30+ languages & platforms
Xbase++

Configure HTTP Basic Authentication with SecureString

See more REST Examples

Demonstrates Rest.SetAuthBasicSecure, which configures HTTP Basic authentication using SecureString objects instead of plaintext strings.

Background. A SecureString keeps sensitive values encrypted in memory, reducing the window in which credentials appear as readable plaintext. This is otherwise equivalent to SetAuthBasic.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL oSsUsername
LOCAL oSsPassword
LOCAL cResponseText

nSuccess := 0

oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    RETURN
ENDIF

//  SetAuthBasicSecure configures HTTP Basic authentication using SecureString objects, which keep
//  the credentials encrypted in memory.
//  Normally you would not hard-code secrets in source.  You should instead obtain them from an
//  interactive prompt, environment variable, or a secrets vault.
oSsUsername := CreateObject("Chilkat.SecureString")
oSsUsername:Append("myUsername")
oSsPassword := CreateObject("Chilkat.SecureString")
oSsPassword:Append("myPassword")

nSuccess := oRest:SetAuthBasicSecure(oSsUsername, oSsPassword)
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    oSsUsername:destroy()
    oSsPassword:destroy()
    RETURN
ENDIF

cResponseText := oRest:FullRequestNoBody("GET", "/api/protected")
IF (oRest:LastMethodSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    oSsUsername:destroy()
    oSsPassword:destroy()
    RETURN
ENDIF

? cResponseText

oRest:destroy()
oSsUsername:destroy()
oSsPassword:destroy()