SSL/TLS error when trying to perform Cielo API transaction

Asked

Viewed 1,277 times

2

All week long I have had problems in calling their API, I get only the following error:

The underlying connection was closed unexpected error in a send

My code called in Restsharp is:

public Transaction Transaction_CreditCard(Transaction transaction)
{
    var request = new RestRequest(Method.POST);
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("content-type", "text/json");
    request.AddHeader("merchantkey", this.merchantKey);
    request.AddHeader("merchantid", this.merchantID);
    request.AddParameter("application/json", JsonConvert.SerializeObject(transaction), ParameterType.RequestBody);
    return Execute<Transaction>(request, this.apiUrl);
}

private T Execute<T>(RestRequest request, string url) where T : new()
{    
    var cliente = new RestClient(url);        
    var response = cliente.Execute<T>(request);

    if (response.ErrorException != null)
    {
        string message = "Erro durante a requisição " + request.Resource;
        var cieloException = new ApplicationException(message, response.ErrorException);       
        throw cieloException;
    }
        return response.Data;
    }

But mine response.ContentLength is equal to 0. I already set up SSL on my site, already add the user-agent and didn’t solve either

What might be going on?

  • You implemented the payment by Cielo ? can send me an example ?

1 answer

5


After a lot of research I managed to solve the error message by inserting the following line in the function Execute:

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

SecurityProtocol is the security protocol that the service point will use for web requests Tls12 I am automatically updating my requests to TLS 2.0 which is the safest protocol, so the request went perfectly.

Browser other questions tagged

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