Skip to content

Instantly share code, notes, and snippets.

@kuharan
Created May 22, 2021 19:33
Show Gist options
  • Save kuharan/28227a0460abb3fd301bf2565921b699 to your computer and use it in GitHub Desktop.
Save kuharan/28227a0460abb3fd301bf2565921b699 to your computer and use it in GitHub Desktop.
This powershell snippet makes a api call to url with a json body converted from csv.
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
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$body = Import-Csv "path\to\body.csv" | ConvertTo-Json
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$response = Invoke-RestMethod 'https://api-url.com' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment