title: Convert cURL to PowerShell Invoke WebRequest
body: <p>I do not know much about APIs, but nothing I have seen seems to get me what I need. </p>
  
  <p>This works in the cmd line:</p>
  
  <pre><code>curl -X POST --user user:password --data-raw "Request=GET%2C%2892837F755%29%2C%28" http://url.com
  </code></pre>
  
  <p>I cannot seem to convert this to anything working in PowerShell. I have tried <a href="https://stackoverflow.com/questions/24672760/powershells-invoke-restmethod-equivalent-of-curl-u-basic-authentication">this</a>, and <a href="https://stackoverflow.com/questions/40381460/powershell-invoke-webrequest-login">this</a>, and <a href="https://stackoverflow.com/questions/27951561/use-invoke-webrequest-with-a-username-and-password-for-basic-authentication-on-t">this</a>, and nothing seems to work. </p>
  
  <p>Anyone got any suggestions?</p>
  
  <p>Thanks to a comment, I tried this:</p>
  
  <pre><code>Invoke-WebRequest -Method Post -UseBasicParsing -Uri "http://example.com/foo?some=param&amp;Request=GET%%2C%%2892837F‌​755%%29%%2C%%28" -Headers @{Authorization=[Convert]::ToBase64String([Text.Encoding]::A‌​SCII.GetBytes('usern‌​ame:password'))}
  </code></pre>
  
  <p>But it returned this:</p>
  
  <pre><code>Invoke-WebRequest :
  401 Authorization Required
  Authorization Required
  This server could not verify that you
  are authorized to access the document
  requested.  Either you supplied the wrong
  credentials (e.g., bad password), or your
  browser doesn't understand how to supply
  the credentials required.
  Apache/2.2.3 (Red Hat) Server at rplus.intdata.com Port 80
  At line:1 char:1
  + Invoke-WebRequest -Method Post -UseBasicParsing -Uri ""http://example ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
  </code></pre>
  
  <p>EDIT2:</p>
  
  <p>I figured out how to see the outgoing request from curl, and it looks like this:</p>
  
  <pre><code>C:\windows\system32&gt;curl -X POST --user user:password --data-raw "Request=GET%2C%2892837F755%29%2C%28" http://url.com
  
  *   Trying 100.100.100.100...
  * TCP_NODELAY set
  * Connected to url.com (100.100.100.100) port 80 (#0)
  * Server auth using Basic with user 'user'
  &gt; POST /url HTTP/1.1
  &gt; Host: url.com
  &gt; Authorization: Basic *****
  &gt; User-Agent: curl/7.52.1
  &gt; Accept: */*
  &gt; Content-Length: 87
  &gt; Content-Type: application/x-www-form-urlencoded
  &gt;
  * upload completely sent off: 87 out of 87 bytes
  * HTTP 1.0, assume close after body
  &lt; HTTP/1.0 200 Script results follow
  &lt; Content-type: text/plain
  &lt;
  "theResponseIExpected"
  * Curl_http_done: called premature == 0
  * Closing connection 0
  </code></pre>
  
  <p>(I changed a bunch of the actual strings in the text above...). </p>
  
  <p>SO, it looks like there's this basic authentication in the header, followed by some 20-digit alphanumeric thing (***** in the text above). What is that? How does curl generate that? If it is some sort of encryption or translation, it looks as if it is only changing the password, and not the user. Not sure if that is the same as what this does -  <code>ToBase64String([Text.Encoding]::ASCII.GetBytes('user:password'))</code></p>
  
  <p>Edit 3:</p>
  
  <p>This seems to work, and seems to get a response, but PowerShell doesnt seem to like it:</p>
  
  <pre><code>$user = "user"
  $pass = "password"
  $pair = "${user}:${pass}"
  
  $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
  $base64 = [System.Convert]::ToBase64String($bytes)
  
  $basicAuthValue = "Basic $base64"
  
  $headers = @{ Authorization = $basicAuthValue }
  Invoke-WebRequest -Uri "url.com?Request=..." -Headers $headers
  </code></pre>
  
  <p>I am now getting the following:</p>
  
  <pre><code>Invoke-WebRequest : The server committed a protocol violation. Section=ResponseStatusLine
  At line:13 char:1
  </code></pre>
  
  <p>I have found a few posts related to this, but they all want me to change a config file. I have tried that, but it does not seem to work. It seems the response is in HTTP1.0, and InvokeWebRequest wants 1.1. Is there a way within this script to let it allow 1.0 responses??</p>