Visual FoxPro
Visual FoxPro
Example: Http.SetUrlVar method
Demonstrates the HTTP SetUrlVar method.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL lcUrl
LOCAL loSbJson
LOCAL lnStatusCode
lnSuccess = 0
loHttp = CreateObject('Chilkat.Http')
lcUrl = "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"
loHttp.SetUrlVar("symbol","MSFT")
loHttp.SetUrlVar("api_key","1234567890ABCDEF")
loSbJson = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb(lcUrl,loSbJson)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loSbJson
CANCEL
ENDIF
lnStatusCode = loHttp.LastStatus
IF (lnStatusCode <> 200) THEN
? "Status code: " + STR(lnStatusCode)
? "Error Message:"
? loSbJson.GetAsString()
ELSE
? "JSON Stock Quote:"
? loSbJson.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}
RELEASE loHttp
RELEASE loSbJson