Sample code for 30+ languages & platforms
Dart

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Dart Downloads

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

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

  final http = CkHttp();

  // To use HTTP Basic authentication:
  http.login = 'myLogin';
  http.password = 'myPassword';
  http.basicAuth = true;

  // Run the test using this URL with the credentials above.  
  // (Works while httpbin.org keeps the test endpoint available.)
  final String jsonResponse;
  try {
    jsonResponse = http.quickGetStr('https://httpbin.org/basic-auth/myLogin/myPassword');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Response status code: ${http.lastStatus}');

  print(jsonResponse);

  // Output:

  // Response status code: 200
  // {
  //   "authenticated": true, 
  //   "user": "myLogin"
  // }
}