SSL / TLS error while attempting to perform Sky API transaction

1

During all week I had problems in the calls to their API, I get only the following error:

  

The underlying connection was closed unexpected error in a submission

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 my response.ContentLength is equal to 0 . I already configured SSL on my site, I already added user-agent and it did not solve either

What could be happening?

    
asked by anonymous 17.08.2018 / 14:26

1 answer

3

After much research I was able to resolve the error message by inserting the following line in the Execute function:

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

SecurityProtocol is the security protocol that the service point will use in Web requests ie setting Tls12 I am automatically updating my requests for TLS 2.0 which is the safest protocol, so the request has occurred perfectly.

    
17.08.2018 / 14:43