![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Java) Example: Http.SetUrlVar methodDemonstrates the HTTP SetUrlVar method.
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} } } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.