Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

c# - The request was aborted: Could not create SSL/TLS secure channel. Using RestRequest in .Net Application

I am building a connection to an external API. Basically I send them a request to an initial URL and they send me some JWK's wwhich have public, private keys that I then extract and construct a certificate from. The second request I'm trying to send though doesn't even get to the point where I can send it out. The certificate constructed looks like a valid certificate and the values send across look like the correct values since I copied them from an example application though something seems to be off.

I read some posts that c# will automatically refuse to send a request if the certificate is not bolted on properly but I've tried exporting it and using pfx format etc.

Does anyone have any idea?

       ' var testClient2 = new RestClient("someaddress");

        ServicePointManager.Expect100Continue = true;
        ServicePointManager.DefaultConnectionLimit = 9999;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

        testClient2.Timeout = -1;
        testClient2.ClientCertificates = new X509CertificateCollection() { certificat };
        testClient2.Proxy = new WebProxy();
        testClient2.PreAuthenticate = true;

        var secondRequest = new RestRequest(Method.POST);
        secondRequest.AddHeader("Accept", "application/json, application/javascript, text/javascript, text/json");
        secondRequest.AddHeader("x-api-key", "somekey");
        secondRequest.AddHeader("Content-Type", "application/jwt");
        secondRequest.AddHeader("charset", "ISO-8859-1");

        secondRequest.AddJsonBody(secondTokenString);

        try
        {
            IRestResponse response2 = testClient2.Execute(secondRequest);
        }
        catch(Exception ex) { 

        }'
question from:https://stackoverflow.com/questions/65920462/the-request-was-aborted-could-not-create-ssl-tls-secure-channel-using-restrequ

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...