Sample code for 30+ languages & platforms
React Native 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 React Native Downloads

React Native
import { Http, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'

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

  const http = new Http();

  try {
    http.setSslClientCertPfx('your.pfx', 'pfx_password');
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  // Get the XML we wish to send in the body of the request.
  const sbXml = new StringBuilder();
  try {
    sbXml.loadFile('qa_data/payload.xml', 'utf-8');
  } catch {
    console.log('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

  const json = new JsonObject();
  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());

  const url = 'https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena';
  const resp = new HttpResponse();
  http.uncommonOptions = 'SendGzipped';
  try {
    await http.httpSbAsync('POST', url, sbXml, 'utf-8', 'application/octet-stream', resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  http.clearHeaders();

  console.log(`response status code: ${resp.statusCode}`);

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