Sample code for 30+ languages & platforms
Dart

POST application/json HTTPS Request

See more HTTP Examples

Demonstrates how to send an HTTPS POST where the request body and response body both have the application/json Content-Type. Also demonstrates how to add a few custom headers to the request.

Chilkat Dart Downloads

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

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

  final http = CkHttp();

  // Add a few custom headers.
  http.setRequestHeader('Client-ID', 'my_client_id');
  http.setRequestHeader('Client-Token', 'my_client_token');

  http.accept = 'application/json';

  final url = 'https://api.fiscallog.eu/sign/v1';
  final jsonRequestBody = '{ .... }';
  final resp = CkHttpResponse();
  try {
    http.httpStr('POST', url, jsonRequestBody, 'utf-8', 'application/json', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Response status code = ${resp.statusCode}');
  final jsonResponseStr = resp.bodyStr;

  print(jsonResponseStr);
}