HTTP-Call (ignore SSL): Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „== Invoke-WebRequest with HTTP Basic Authentication == <source lang="powershell"> $URL = "https://your-url.ch:port" $EncodedCredentials = [System.Convert]::ToB…“) |
Admin (Diskussion | Beiträge) K (Admin verschob die Seite HTTP-Call nach HTTP-Call (ignore SSL), ohne dabei eine Weiterleitung anzulegen) |
||
(6 dazwischenliegende Versionen des gleichen Benutzers werden nicht angezeigt) | |||
Zeile 2: | Zeile 2: | ||
<source lang="powershell"> | <source lang="powershell"> | ||
$URL = "https://your-url.ch:port" | $URL = "https://your-url.ch:port" | ||
− | $EncodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes( | + | $CredPair = "<username>:<password>" |
+ | $EncodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($CredPair)) | ||
$Headers = @{Authorization = "Basic $encodedCredentials"} | $Headers = @{Authorization = "Basic $encodedCredentials"} | ||
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">[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 </source> | ||
+ | |||
+ | == Allow the use of self-signed SSL certificates == | ||
+ | <source lang="powershell">[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True} </source> | ||
Zeile 23: | Zeile 31: | ||
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy | [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy | ||
+ | [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Ssl3, [System.Net.SecurityProtocolType]::Tls, [System.Net.SecurityProtocolType]::Tls11, [System.Net.SecurityProtocolType]::Tls12 | ||
</source> | </source> | ||
Aktuelle Version vom 11. Februar 2021, 08:57 Uhr
Inhaltsverzeichnis
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
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Allow the use of self-signed SSL certificates
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$True}
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 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Ssl3, [System.Net.SecurityProtocolType]::Tls, [System.Net.SecurityProtocolType]::Tls11, [System.Net.SecurityProtocolType]::Tls12