I am trying to connect to an external api website. I don’t know details around how REST/JSON works, but I want to use powershell to download a csv file via GET method. I could successfully connect via CURL, but with powershell I cannot, and am exhausted.
CURL:
curl.exe -v -H “Accept: application/json” -u APIKEY: “https://”
Powershell:
Invoke-RestMethod -Uri ‘https://’ -Headers @{“AUTHORIZATION”="Basic "} -Method Get
I always receive following error:
the underlying connection was closed an unexpected error occurred on a send and the underlying connection was closed an unexpected error occurred on a receive
I tried using following script for certificate:
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”
Source: .net - Powershell v3 Invoke-WebRequest HTTPS error - Stack Overflow
still no luck.
Can someone help me understand what I am doing wrong?