TLS 1.2 Requests with Restsharp

Asked

Viewed 911 times

0

I need to use TLS 1.2 in an HTTP request with Restsharp.

Every time I make a POST, it reports the error "The underlying connection was closed: Could not establish trust for secure SSL/TLS channel.".

private void CriarServicoWebEEnviar(string url, byte[] sig)
    {
        ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
        var client = new RestClient(url);

        var request = new RestRequest(Method.POST);
        request.AddHeader("content-type", "application/pkcs7-signature");
        request.AddParameter("application/pkcs7-signature", sig, ParameterType.RequestBody);

        IRestResponse response = client.Execute(request);
    }

I’m using Visual Studio 2010 with . NET Framework 4.0

  • are you sure you are using TLS 1.2? in your code does not show this, which version of the Framework is using?

  • Ricardo, I’m using framework 4.0. I updated the question with more information.

  • just to confirm... is with https and knocking with the indicated port?

1 answer

2

Just add this line before the run:

System.Net.ServicePointManager.SecurityProtocol =  SecurityProtocolType.Tls12;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.