我想向在 IIS 服务器下运行的客户端 .NET 应用程序添加相互身份验证(它是一个调用另一个 Web 服务的 Web 服务)。客户端应用程序从文件加载客户端证书,并且在我的开发计算机上使用以下代码可以正常工作(我尝试使用 .NET 4.6.2 的 Windows 7 和 Windows 10):
var handler = new WebRequestHandler();
var certificate = new X509Certificate2(clientCertPath); -- PFX file with client cert and private key
handler.ClientCertificates.Add(certificate);
handler.AuthenticationLevel = AuthenticationLevel.MutualAuthRequired;
client = new HttpClient(handler);
Run Code Online (Sandbox Code Playgroud)
但是,当将此代码部署到生产 Windows 2016 Server 计算机时,应用程序会抛出异常The request was aborted: Could not create SSL/TLS secure channel.
我启用了跟踪,System.Net这是我在日志中看到的
SecureChannel#66407304 - Certificate is of type X509Certificate2 and contains the private key.
AcquireCredentialsHandle(package = Microsoft Unified Security Protocol …Run Code Online (Sandbox Code Playgroud) c# iis client-certificates dotnet-httpclient mutual-authentication
例如,我有多个构造函数的数据类型
data AB = A
{
ab :: Text
, a :: Text
}
| B
{
ab :: Text
, b :: Text
} deriving (Generic)
Run Code Online (Sandbox Code Playgroud)
现在,当我使用 Aeson 将其序列化为A以下 JSON 时:
{
"tag": "A",
"ab": "some text",
"a": "some text"
}
Run Code Online (Sandbox Code Playgroud)
我知道可以用来SumEncoding操纵构造函数的处理方式,但找不到我想要的。
是否有可能以某种方式省略tag序列化 JSON 中的字段?我只需要一种方式序列化(没有理由保留它来反序列化它),但是数据类型非常大,无法编写如何手动序列化它。
我有一个转换ByteArray?为base64 的方法,String?因此,如果null输出了参数,也会这样null。这是它的实现:
fun toBase64String(array: ByteArray?): String? = if(array == null) null else
Base64.getEncoder().encodeToString(array)
Run Code Online (Sandbox Code Playgroud)
但是当我传入不为null的ByteArray方法时String?,会返回预期的结果。有没有一种使它通用的方法,这样的用例将是可能的:
val base64 = toBase64String(ByteArray(4))
Run Code Online (Sandbox Code Playgroud)
哪里base64是类型,String而不是String?因为参数不可为空?
我刚刚开始与Kotlin一起工作,可能不知道使它成为可能的语言功能。