C# HttpClient请求中未包含嵌入式证书(c)
我正在尝试向外部API发送SSL证书,以便通过其服务进行身份验证。我收到错误:“请求被中止:无法创建SSL/TLS安全通道。” 我与API的托管公司进行了交谈,他们说他们更改了服务以接受任何SSL证书,只是为了确保我确实发送了SSL证书,我收到了相同的错误,因此请求中似乎没有包含SSL证书C# HttpClient请求中未包含嵌入式证书(c),c#,.net,ssl,C#,.net,Ssl,我正在尝试向外部API发送SSL证书,以便通过其服务进行身份验证。我收到错误:“请求被中止:无法创建SSL/TLS安全通道。” 我与API的托管公司进行了交谈,他们说他们更改了服务以接受任何SSL证书,只是为了确保我确实发送了SSL证书,我收到了相同的错误,因此请求中似乎没有包含SSL证书 var clientHandler = new WebRequestHandler(); clientHandler.ClientCertificates.Add(GetEmbeddedCert()); S
var clientHandler = new WebRequestHandler();
clientHandler.ClientCertificates.Add(GetEmbeddedCert());
ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;
using (var client = new HttpClient(clientHandler))
{
return client.PostAsync(_plugin.EndPoint.ToString().Trim(),
new StringContent(hl7)).Result;
}
我使用的嵌入式证书的构建操作设置为“嵌入式资源”:
private X509Certificate2 GetEmbeddedCert()
{
使用(Stream=Assembly.getExecutionGassembly()
.GetManifestResourceStream(GetType(),“mycert.cer”))
{
字节[]字节=新字节[stream.Length];
for(intidx=0;idx
有人知道为什么SSL证书没有被发送,或者为什么我会出现上述错误吗
谢谢您可以尝试在web浏览器中使用证书吗?它有效吗?由于某种原因,当我在浏览器中导航到url时,证书不在弹出的证书列表中,但我使用了另一个证书,我得到了一个405方法,不允许@markokatar
private X509Certificate2 GetEmbeddedCert()
{
using (Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(GetType(), "mycert.cer"))
{
byte[] bytes = new byte[stream.Length];
for (int idx = 0; idx < stream.Length; idx++)
bytes[idx] = (byte)stream.ReadByte();
X509Certificate2 cert = new X509Certificate2();
cert.Import(bytes);
return cert;
}
}