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

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        try {
            http.setSslClientCertPfx("your.pfx", "pfx_password");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Get the XML we wish to send in the body of the request.
        StringBuilder sbXml = new StringBuilder();
        try {
            sbXml.loadFile("qa_data/payload.xml", "utf-8");
        } catch (ChilkatException e) {
            System.out.println("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

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

        String url = "https://pruesarrerak.bizkaia.eus/N3B4000M/aurkezpena";
        HttpResponse resp = new HttpResponse();
        http.setUncommonOptions("SendGzipped");
        try {
            http.httpSb("POST", url, sbXml, "utf-8", "application/octet-stream", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        http.clearHeaders();

        System.out.println("response status code: " + resp.getStatusCode());

        // Examine the response (it is already decompressed)
        System.out.println("response body:");
        System.out.println(resp.getBodyStr());
    }
}