Sample code for 30+ languages & platforms
B4X

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 B4X Downloads

B4X
Dim success As Boolean = False

Dim rest As ChilkatRest
rest.Initialize("rest")
Dim bTls As Boolean = True
Dim bAutoReconnect As Boolean = True
success = rest.Connect("example.com", 443, bTls, bAutoReconnect)
If success = False Then
    Log(rest.LastErrorText)
    Return
End If


'  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.
Dim ssUsername As ChilkatSecureString
ssUsername.Initialize
ssUsername.Append("myUsername")
Dim ssPassword As ChilkatSecureString
ssPassword.Initialize
ssPassword.Append("myPassword")

success = rest.SetAuthBasicSecure(ssUsername, ssPassword)
If success = False Then
    Log(rest.LastErrorText)
    Return
End If


Dim responseText As String = rest.FullRequestNoBody("GET", "/api/protected")
If rest.LastMethodSuccess = False Then
    Log(rest.LastErrorText)
    Return
End If

Log(responseText)