Utilizzando Invoke-WebRequest e Invoke-RestMethod di Powershell v3, ho utilizzato con successo il metodo POST per pubblicare un file json su un sito Web https.
Il comando che sto usando è
$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
Tuttavia, quando provo a utilizzare il metodo GET come:
Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Method GET
Viene restituito il seguente errore
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
Ho tentato di utilizzare il seguente codice per ignorare il certificato SSL, ma non sono sicuro che stia effettivamente facendo qualcosa.
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Qualcuno può fornire qualche guida su cosa potrebbe andare storto qui e su come risolverlo?
Grazie
Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. potresti provare a esplorare $ Error [0] .Exception.InnerException per maggiori informazioni .. .
Invoke-RestMethodoInvoke-WebRequest?