Sample code for 30+ languages & platforms
Java

HttpPostJson2 Example

See more HTTP Examples

Demonstrates use of the HttpPostJson2 method.

Chilkat Java Downloads

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

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

        // See PostJson2Async Example for the async equivalent of this example.

        Http http = new Http();

        // Sends a POST equivalent to the following CURL command:

        // curl -X POST https://sandbox.plaid.com/institutions/get \
        //   -H 'content-type: application/json' \
        //   -d '{
        //     "client_id": String,
        //     "secret":String,
        //     "count": Number,
        //     "offset": Number
        //   }'

        // Suppress some default headers that would automatically added..
ERROR: Property not in Chilkat2 Java: Http.AcceptCharset
        http.ERROR("");
        http.setUserAgent("");
ERROR: Property not in Chilkat2 Java: Http.AcceptLanguage
        http.ERROR("");
        http.setAllowGzip(false);

        String jsonBody = "{\"client_id\": \"PLAID_CLIENT_ID\", \"secret\":\"PLAID_SECRET\", \"count\": 10, \"offset\": 0}";
ERROR: Method not in Chilkat2 Java: Http.PostJson2
        HttpResponse resp = http.ERROR();
        if (!http.getLastMethodSuccess()) {
            System.out.println(http.getLastErrorText());
            return;
        }

        int statusCode = resp.getStatusCode();
        System.out.println("Response status code = " + statusCode);

        // Examine the JSON response..
        JsonObject json = new JsonObject();
        json.load(resp.getBodyStr());
        json.setEmitCompact(false);
        System.out.println("JSON Response Body:");
        System.out.println(json.emit());

        resp.close();
    }
}