title: Invoke-RestMethod {Message: "The request is invalid."}
body: <p>The following curl command successfully makes the API call and returns the expected output:</p>
  
  <pre><code>curl -X GET "https://&lt;rootURI&gt;/calc/add?a={14}&amp;b={22}" -H "Ocp-Apim-Subscription-Key: &lt;key value&gt;" --insecure
  </code></pre>
  
  <p>When I try using Invoke-RestMethod however I receive the following response:</p>
  
  <pre><code>ERROR: Invoke-RestMethod : {"Message":"The request is invalid."}
  </code></pre>
  
  <p>My PowerShell code snippet is:</p>
  
  <pre><code>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
  
  $header = @{ 'Ocp-Apim-Subscription-Key' = '&lt;key value&gt;' }
  $uri = 'https://&lt;rootURI&gt;/calc/add?a={14}&amp;b={22}'
  
  Invoke-RestMethod -Method Get -Uri $uri -Headers $header
  </code></pre>
  
  <p>I also tried to force the use of TLS 1.2 with the following line and got the same result.</p>
  
  <pre><code>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  </code></pre>
  
  <p>Any ideas?</p>