Unofficial Content

The underlying connection was closed 

When calling a service (Http, Rest or Soap), it could detail the previous error.

Cause/Solution:

1. It is a service, which was moved from SSL to Transport Layer Security (1.2 or higher) 

Solution: In order to consume it from .NET environments, add the following:

csharp System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

More Information here

Important: Also the error could be:  "The request was aborted: Could not create SSL/TLS secure channel."

2. It is a service, which does not accept the 100-continue header. It could also detail the "505 Http Version Not Supported" message.

Solution: In order to consume it from .NET environments, add the following:

csharp System.Net.ServicePointManager.Expect100Continue = false;

More Information here or here 

3. It is a service, which can only be called from browsers

Solution: In order to consume it, it is neccessary to add the User-Agent header, using the HttpClient data type add the following:

&httpclient.AddHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) ....")
&httpclient.Host = "host"
&httpclient.Port = 443
&httpclient.Secure = 1
&httpclient.BaseUrl = "/"
&httpclient.Execute("GET", "ResourceName")   // or &httpclient.Execute("POST", "ResourceName")

4. It is a service running under Https protocol which has some certificate validation error  

Solution: In order to consume it from .NET environments, add the following:

csharp System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

More Information here

Last update: April 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant