Sample code for 30+ languages & platforms
Dart

Example: Http.DownloadSb method

See more HTTP Examples

Demonstrates the DownloadSb method.

Chilkat Dart Downloads

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

void main() {
  var success = false;

  final http = CkHttp();
  http.keepResponseBody = true;

  final sb = CkStringBuilder();
  success = true;
  try {
    http.downloadSb('https://chilkatsoft.com/testData/helloWorld.txt', 'utf-8', sb);
  } on ChilkatException {
    success = false;
  }

  final statusCode = http.lastStatus;
  if (!success) {
    if (statusCode == 0) {
      // Unable to either send the request or get the response.
      print(http.lastErrorText);
    } else {
      // We got a response, but the status code was not in the 200s
      print('Response status code: $statusCode');
      // Examine the response body.
      print('Response body:');
      print(http.lastResponseBody);
    }

    print('Download failed.');
  } else {
    print('Download success, response status = $statusCode');
    print(sb.getAsString());
  }
}