Sample code for 30+ languages & platforms
Java

Example: Http.SetUrlVar method

Demonstrates the HTTP SetUrlVar method.

Chilkat Java Downloads

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

public class ChilkatExample {

    public static void main(String[] args) {
        Http http = new Http();

        String url = "https://finnhub.io/api/v1/quote?symbol={$symbol}&token={$api_key}";

        // When the request is sent, the {$symbol} is replaced with "MSFT"
        // and the {$api_key} is replaced with "1234567890ABCDEF"
        http.setUrlVar("symbol", "MSFT");
        http.setUrlVar("api_key", "1234567890ABCDEF");

        StringBuilder sbJson = new StringBuilder();
        try {
            http.quickGetSb(url, sbJson);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        int statusCode = http.getLastStatus();
        if (statusCode != 200) {
            System.out.println("Status code: " + statusCode);
            System.out.println("Error Message:");
            System.out.println(sbJson.getAsString());
        } else {
            System.out.println("JSON Stock Quote:");
            System.out.println(sbJson.getAsString());
        }

        // Output:

        // JSON Stock Quote:
        // {"c":522.98,"d":0.5,"dp":0.0957,"h":524.51,"l":520.86,"o":524.28,"pc":522.48,"t":1755271948}
    }
}