Difference between revisions of "Invoke-webrequest ignore ssl cert"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with "``` if (-not("dummy" -as [type])) { add-type -TypeDefinition @" using System; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certifica...")
 
 
Line 1: Line 1:
 +
```
 +
Invoke-WebRequest https://10.x.x.x/foo/bar -Headers @{ host="api.example.com" } -SkipCertificateCheck
 +
```
 +
 +
The long without -SkipCertificateCheck
 
```
 
```
 
if (-not("dummy" -as [type])) {
 
if (-not("dummy" -as [type])) {

Latest revision as of 16:43, 7 September 2023

Invoke-WebRequest https://10.x.x.x/foo/bar -Headers @{ host="api.example.com" } -SkipCertificateCheck

The long without -SkipCertificateCheck

if (-not("dummy" -as [type])) {
    add-type -TypeDefinition @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

public static class Dummy {
    public static bool ReturnTrue(object sender,
        X509Certificate certificate,
        X509Chain chain,
        SslPolicyErrors sslPolicyErrors) { return true; }

    public static RemoteCertificateValidationCallback GetDelegate() {
        return new RemoteCertificateValidationCallback(Dummy.ReturnTrue);
    }
}
"@
}

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate()