(PowerShell) HTTP Basic Authentication
Demonstrates how to use HTTP Basic authentication.
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$http = New-Object Chilkat.Http
# To use HTTP Basic authentication:
$http.Login = "myLogin"
$http.Password = "myPassword"
$http.BasicAuth = $true
# Run the test using this URL with the credentials above.
# (Works while httpbin.org keeps the test endpoint available.)
$jsonResponse = $http.QuickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword")
if ($http.LastMethodSuccess -eq $false) {
$($http.LastErrorText)
exit
}
$("Response status code: " + $http.LastStatus)
$($jsonResponse)
# Output:
# Response status code: 200
# {
# "authenticated": true,
# "user": "myLogin"
# }
|