Restsharp :The SSL connection could not be established

0

An app is run on netcore2.1.5,win7.

  1. I use restsharp to request the API and need to take client certificates, always return the error:

The SSL connection could not be established, see inner exception. Authentication failed, see inner exception

The inner exception content:

System.ComponentModel.Win32Exception (0x80090326): 接收到的消息异常,或格式不正确。

English version:

"The message received is abnormal or not formatted correctly"

  1. I user postman to request the API and take the same crt file and response the result result.

My code on below:

string clientCertfile = @"E:\https\client.crt";
var client = new RestClient("https://apiserver/iocm/app/sec/v1.1.0/login");
X509Certificate2 certificates = new X509Certificate2(clientCertfile);
//X509Certificate2 certificates = GetMyX509Certificate(clientCertfile);
client.ClientCertificates = new X509Certificate2Collection(){ certificates };
client.RemoteCertificateValidationCallback = 
    new RemoteCertificateValidationCallback(OnRemoteCertificateValidationCallback);

var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("appId", "rIsyJsnMtOrKfpSO90");
request.AddParameter("secret", "8v0fH0ztunjP1oXT");
IRestResponse response = client.Execute(request);

postman test image

asp.net-core
restsharp
asp.net-core-2.1
client-certificates
asked on Stack Overflow Nov 23, 2018 by jasonyush • edited Nov 23, 2018 by p u

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0