Brenners Daniel
Brenners Daniel

Reputation: 419

Powershell Invoke-WebRequest Error - Interacting with Azure Databricks

I use PowerShell in the desktop PSVersion 5.1.14393.2155. I am trying to use Invoke-WebRequest. The Azure VM used is not part of a firewall etc. So I should not get any problems or restrictions here.

I receive the following error:

Invoke-WebRequest -Method Post -Uri 'https://IpAddress/resource'
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line: 1 char:1
+ Invoke-WebRequest -Method Post -Uri 'https://IpAddress/resource ...
+
    + CategoryInfo         : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId: WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestComand

I already did my call with a Powershell script. In addition, I have called the command parameter for parameter on request in my Powershell. I was able to test already some Stackoverflow articles. No success.

Already tested:

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

$result = Invoke-WebRequest -Uri "https://IpAddress/resource"

With reference to the article Powershell v3 Invoke-WebRequest HTTPS error, I could understand and test these steps so far.

What goes wrong here with me?

Upvotes: 0

Views: 1176

Answers (2)

Brenners Daniel
Brenners Daniel

Reputation: 419

Thank you for your answer. I was able to test this this morning. That's possible. My final solution now looks like this in the script.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://IpAddress/resource" -Method Post -ContentType "application/xml"

Upvotes: 0

Fabrizio Accatino
Fabrizio Accatino

Reputation: 2292

Try to force TLS 1.2

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Upvotes: 2

Related Questions