更新时间:2022-02-26 08:54:29
最典型的方法是然后在应用启动时将其注册:
Then register it somewhere in your app startup:
FlurlHttp.ConfigureClient("https://theapi.com", cli =>
cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());
Flurl默认情况下在每个主机上重用相同的HttpClient
实例,因此配置此方式意味着对theapi.com
的每次调用都将允许使用不受信任的证书.与将HttpClient
传递给FlurlClient
构造函数相比,此方法的优势在于,它可以使此配置脱离侧面",并且在您以更典型/更不冗长的方式使用Flurl时可以使用:
Flurl reuses the same HttpClient
instance per host by default, so configuring this way means that every call to theapi.com
will allow the use of the untrusted cert. The advantage of this over passing an HttpClient
to a FlurlClient
constructor is that it keeps this configuration "off to the side" and works when you use Flurl in the more typical/less verbose way:
await "https://theapi.com/endpoint".GetJsonAsync();