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

TicketBAI -- Send HTTP POST

See more TicketBAI Examples

Demonstrates how to send a TicketBAI POST and get the response.

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();

  try {
    http.setSslClientCertPfx('your.pfx', 'pfx_password');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Get the XML we wish to send in the body of the request.
  final sbXml = CkStringBuilder();
  try {
    sbXml.loadFile('qa_data/payload.xml', 'utf-8');
  } on ChilkatException {
    print('Failed to load XML that is to be the HTTP request body');
    return;
  }

  // Build the following JSON

  // { 
  //     "con": "LROE", 
  //     "apa": "1.1", 
  //     "inte": { 
  //         "nif": "número de identificación fiscal", 
  //         "nrs": "nombre o Razón social", 
  //         "ap1": "primer apellido", 
  //         "ap2": "segundo apellido" 
  //     }, 
  //     "drs": { 
  //     "mode": "140", 
  //     "ejer": "ejercicio" 
  //     } 
  // }

  // Use this online tool to generate code from sample JSON: 
  // Generate Code to Create JSON

  final json = CkJsonObject();
  json.updateString('con', 'LROE');
  json.updateString('apa', '1.1');
  json.updateString('inte.nif', 'número de identificación fiscal');
  json.updateString('inte.nrs', 'nombre o Razón social');
  json.updateString('inte.ap1', 'primer apellido');
  json.updateString('inte.ap2', 'segundo apellido');
  json.updateString('drs.mode', '140');
  json.updateString('drs.ejer', 'ejercicio');

  // Add required headers...
  http.setRequestHeader('eus-bizkaia-n3-version', '1.0');
  http.setRequestHeader('eus-bizkaia-n3-content-type', 'application/xml');
  http.setRequestHeader('eus-bizkaia-n3-data', json.emit());

  final url = 'https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena';
  final resp = CkHttpResponse();
  http.uncommonOptions = 'SendGzipped';
  try {
    http.httpSb('POST', url, sbXml, 'utf-8', 'application/octet-stream', resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  http.clearHeaders();

  print('response status code: ${resp.statusCode}');

  // Examine the response (it is already decompressed)
  print('response body:');
  print(resp.bodyStr);
}