0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

HttpClientで証明書の検証をスキップする

Posted at

さすがに社内も https が増えてきたものの、自己署名が多いので検証をスキップする方法を整理しておく。

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

青い PowerShell の Invoke-WebRequest は中身が古いので、HttpClient を使うようにするのが良いらしい。認証とかどうするんやろ?

Add-Type -AssemblyName System.Net.Http

$client = New-Object System.Net.Http.HttpClient
$response = $client.GetAsync("https://192.168.xxx.yyy").Result
$content = $response.Content.ReadAsStringAsync().Result
Write-Output $content

黒い PowerShell の Invoke-WebRequest は面倒なことをしなくても良い。

invoke-webrequest https://192.168.xxx.yyy -SkipCertificateCheck

さすがに青い PowerShell だけで戦うのは過酷。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?