Xbase++
Xbase++
HTTP Basic Authentication Test
Demonstrates how to do HTTP basic authentication using Chilkat.Chilkat Xbase++ Downloads
LOCAL oHttp
LOCAL cJsonResponse
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// To use HTTP Basic authentication:
oHttp:Login := "myLogin"
oHttp:Password := "myPassword"
oHttp:BasicAuth := 1
// Run the test using this URL with the credentials above.
// (Works while httpbin.org keeps the test endpoint available.)
cJsonResponse := oHttp:QuickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword")
IF (oHttp:LastMethodSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
RETURN
ENDIF
? "Response status code: " + Str(oHttp:LastStatus)
? cJsonResponse
// Output:
// Response status code: 200
// {
// "authenticated": true,
// "user": "myLogin"
// }
oHttp:destroy()