(PureBasic) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; To use HTTP Basic authentication:
CkHttp::setCkLogin(http, "myLogin")
CkHttp::setCkPassword(http, "myPassword")
CkHttp::setCkBasicAuth(http, 1)
; Run the test using this URL with the credentials above.
; (Works while httpbin.org keeps the test endpoint available.)
jsonResponse.s = CkHttp::ckQuickGetStr(http,"https://httpbin.org/basic-auth/myLogin/myPassword")
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
ProcedureReturn
EndIf
Debug "Response status code: " + Str(CkHttp::ckLastStatus(http))
Debug jsonResponse
; Output:
; Response status code: 200
; {
; "authenticated": true,
; "user": "myLogin"
; }
CkHttp::ckDispose(http)
ProcedureReturn
EndProcedure
|