Sample code for 30+ languages & platforms
Dart

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

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final rest = CkRest();
  final bTls = true;
  final bAutoReconnect = true;
  try {
    rest.connect('example.com', 443, bTls, bAutoReconnect);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // 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.
  final ssUsername = CkSecureString();
  ssUsername.append('myUsername');
  final ssPassword = CkSecureString();
  ssPassword.append('myPassword');

  try {
    rest.setAuthBasicSecure(ssUsername, ssPassword);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final String responseText;
  try {
    responseText = rest.fullRequestNoBody('GET', '/api/protected');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print(responseText);
}