HTTP-Call (ignore SSL): Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „== Invoke-WebRequest with HTTP Basic Authentication == <source lang="powershell"> $URL = "https://your-url.ch:port" $EncodedCredentials = [System.Convert]::ToB…“)
 
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("<username>:<password>"))
+
$CredPair = "<username>:<password>"
 +
$EncodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($CredPair))
 
$Headers = @{Authorization = "Basic $encodedCredentials"}
 
$Headers = @{Authorization = "Basic $encodedCredentials"}
  

Version vom 14. September 2018, 11:52 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


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