HTTP-Call (ignore SSL): Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) |
Admin (Diskussion | Beiträge) |
||
Zeile 8: | Zeile 8: | ||
Invoke-WebRequest -Uri $URL -Method Get -Headers $Headers | Invoke-WebRequest -Uri $URL -Method Get -Headers $Headers | ||
</source> | </source> | ||
+ | |||
+ | |||
+ | == Force PowerShell to use TLS 1.2 == | ||
+ | <source lang="powershell">[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 </source> | ||
Version vom 11. Mai 2020, 13:22 Uhr
Invoke-WebRequest with HTTP Basic Authentication
$URL = "https://your-url.ch:port" $CredPair = "<username>:<password>" $EncodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($CredPair)) $Headers = @{Authorization = "Basic $encodedCredentials"} Invoke-WebRequest -Uri $URL -Method Get -Headers $Headers
Force PowerShell to use TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Ignore SSL Certificate
add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy