Xbase++
Xbase++
Example: Http.SetUrlVar method
Demonstrates the HTTP SetUrlVar method.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL cUrl
LOCAL oSbJson
LOCAL nStatusCode
nSuccess := 0
oHttp := CreateObject("Chilkat.Http")
cUrl := "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"
oHttp:SetUrlVar("symbol", "MSFT")
oHttp:SetUrlVar("api_key", "1234567890ABCDEF")
oSbJson := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb(cUrl, oSbJson)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbJson:destroy()
RETURN
ENDIF
nStatusCode := oHttp:LastStatus
IF (nStatusCode != 200)
? "Status code: " + Str(nStatusCode)
? "Error Message:"
? oSbJson:GetAsString()
ELSE
? "JSON Stock Quote:"
? oSbJson:GetAsString()
ENDIF
// 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}
oHttp:destroy()
oSbJson:destroy()