haf / Http.fs

A simple, functional HTTP client library for F#
322 stars 43 forks source link

Self signed #147

Open haf opened 6 years ago

haf commented 6 years ago

https://gist.github.com/benhysell/10c1eb546bd3401ee50f https://stackoverflow.com/questions/28406226/how-to-import-private-key-of-self-signed-certificate-using-certmgr-in-mono#31330399

seanamos commented 6 years ago

Not sure if related or this will help you @haf

The way I do this at the moment is something like:

use dangerousHttpHandler =
    new HttpClientHandler(
        // check:
        // https://github.com/dotnet/corefx/issues/24774
        // https://github.com/dotnet/corefx/issues/19709
        ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator)

let dangerousHttpClient = new HttpClient (dangerousHttpHandler)

let createDangerousRequest (method: HttpMethod) (url: string) =
    new Uri (url)
    |> Request.createWithClient dangerousHttpClient method

let request =
    "https://localhost" // self-signed
    |> createDangerousRequest Get

There could be more functions baked into Http.Fs to make it less cumbersome but the API surface is flexible enough.