En utilisant les méthodes Invoke-WebRequest et Invoke-RestMethod de Powershell v3, j'ai réussi à utiliser la méthode POST pour envoyer un fichier json à un site web https.
La commande que j'utilise est
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("cert.crt")
Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Body $json -ContentType application/json -Method POST
Cependant, lorsque j'essaie d'utiliser la méthode GET comme :
Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Method GET
L'erreur suivante est renvoyée
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At line:8 char:11
+ $output = Invoke-RestMethod -Uri https://IPADDRESS/resource -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
J'ai essayé d'utiliser le code suivant pour ignorer le certificat SSL, mais je ne suis pas sûr qu'il fasse quoi que ce soit.
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Quelqu'un peut-il fournir des conseils sur ce qui pourrait se passer ici et sur la façon de le réparer ?
Gracias