Sample code for 30+ languages & platforms
Dart Requires Chilkat v11.0.0+

HTTP POST with Binary Data in Request Body

See more HTTP Examples

Do an HTTPS POST with a binary request body.

Chilkat Dart Downloads

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

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

  final http = CkHttp();

  final fac = CkFileAccess();

  final reqBody = fac.readEntireFile('qa_data/pdf/helloWorld.pdf');

  final resp = CkHttpResponse();
  try {
    http.httpBinary('POST', 'https://example.com/something', reqBody, 'application/pdf', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final responseStatusCode = resp.statusCode;
  print('Status code: $responseStatusCode');

  // For example, if the response is XML, JSON, HTML, etc.
  print('response body:');
  print(resp.bodyStr);
}