使用F#连接时如何接受SSL证书?

unj*_*nj2 4 ssl f# http

我试图连接到HTTPS页面.在C#中,我可以编写一行代码,要求C#使用该行轻松连接到HTTPS

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Run Code Online (Sandbox Code Playgroud)

我如何使其适应f#?

open System.Net
open System.IO

let url = "https://..."

let mutable request = HttpWebRequest.Create(url)
request.Method <- "GET"  
request.ContentType <- "multipart/form-data"

ServicePointManager.ServerCertificateValidationCallback = fun -> true ???? 

let mutable resp = request.GetResponse()

let fn =
    for i = 1 to 10 do
        request <- WebRequest.Create(url)
        resp <- request.GetResponse()
Run Code Online (Sandbox Code Playgroud)

Dan*_*iel 12

ServicePointManager.ServerCertificateValidationCallback <-
  System.Net.Security.RemoteCertificateValidationCallback(fun _ _ _ _ -> true)
Run Code Online (Sandbox Code Playgroud)

以下也适用:

System.Net.ServicePointManager.ServerCertificateValidationCallback <- 
  (fun _ _ _ _ -> true) //four underscores (and seven years ago?)
Run Code Online (Sandbox Code Playgroud)

RemoteCertificateValidationCallback具有以下签名:

public delegate bool RemoteCertificateValidationCallback(
    Object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors
)
Run Code Online (Sandbox Code Playgroud)

由于函数参数发生了模式匹配,并且您忽略了所有四个参数,因此可以为每个参数替换通配符模式(下划线),这是表示参数未使用的惯用方法.