无法使用 F# 和 RestSharp for Mailgun 对 REST Api 进行身份验证

Unable to Authenticate REST Api using F# and RestSharp for Mailgun

我正尝试在 F# 中使用 restsharp 来调用 Mailgun API。

我根据 Mailgun 的示例 C# 代码对其进行了建模,但无法运行。

问题代码为:

    let client: RestClient = 
        new RestClient(
            BaseUrl = Uri("https://api.mailgun.net/v3")
        )
        
    client.Authenticator = new HttpBasicAuthenticator("","") 

此表达式应具有 IAuthenticator' 类型,但此处具有 'HttpBasicAuthenticator'

类型

似乎某个继承类型与预期类型不同,这对我来说没有意义。 HttpBasicAuthenticator 对象说它继承自 authentocatorBase

我还没有测试过,但很可能您必须将新对象转换为界面。 F# 需要它。

client.Authenticator = new HttpBasicAuthenticator("","") :> IAuthenticator

看看https://fsharpforfunandprofit.com/posts/interfaces/