title: REST-API Basic Authentication and Invoke-WebRequest via Powershell
body: <p>Trying to connect to a REST-API via Powershell client. When testing the endpoint in Postman, I have no problems at all. Here's the main part of the function (I have a <code>[pscredential]$Creds</code> parameter that I use to get the username and password):</p>
  
  <pre><code>[string]$username = $Creds.UserName
  [string]$password = (New-Object System.Net.NetworkCredential($Creds.UserName, $Creds.Password, 'Null')).Password
  [string]$authorizationInfo= ([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(('{0}:{1}' -f $username, $password))))
  
  Invoke-WebRequest -Uri "https://$($HostName)/api/" -Method Get -Headers @{Authorization = ('Basic {0}' -f $authorizationInfo)}
  </code></pre>
  
  <p>For some reason the <code>Authorization</code> header is different in my script than in Postman. I can even copy the <code>Authorization</code> header out of Postman and paste it into the <code>-Headers</code> parameter and everything works fine. I just don't see where I'm getting this wrong.</p>