Sample code for 30+ languages & platforms
Java

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 Java Downloads

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

public class ChilkatExample {

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

        Http http = new Http();

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

        http.setAccept("application/json");

        String url = "https://api.fiscallog.eu/sign/v1";
        String jsonRequestBody = "{ .... }";
        HttpResponse resp = new HttpResponse();
        try {
            http.httpStr("POST", url, jsonRequestBody, "utf-8", "application/json", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response status code = " + resp.getStatusCode());
        String jsonResponseStr = resp.getBodyStr();

        System.out.println(jsonResponseStr);
    }
}