Sample code for 30+ languages & platforms
Java

Example: Http.SetUrlVar method

Demonstrates the HTTP SetUrlVar method.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkHttp http = new CkHttp();

    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");

    CkStringBuilder sbJson = new CkStringBuilder();
    success = http.QuickGetSb(url,sbJson);
    if (success == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    int statusCode = http.get_LastStatus();
    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}
  }
}