342
Views
4
Comments
Consume Rest API - the underlying connection was closed: An unexpected error occurred
Question

Hi there,


I have consumed a REST API in my web application. In order to transfer files in the API call, in the header, I have implemented the content-Type of multipart/form-data.

When I tested with small files (around 8-10kb), the API call can go through successfully. However, when I turned to use normal excel or PDF files which are around 200-500kb, the API calls failed.

At the very beginning, I thought it was due to the size of the files. So I tested in Postman with even larger files. They all got through. So, obviously, the key issue is not about the file size.

Then I fetched the exception message - "the underlying connection was closed: An unexpected error occurred on a send".

I've seen quite a few posts related to this error message. And a few key terms mentioned include updating the .NET Framework, version of TLS certificate, etc. But none explains how to check or modify the specs in the Outsystems service studio environment or web service centre.

To share more insights with you guys, I attached the sreenshot of the service centre stack error messages.

So, any hints would be great. Thanks in advance.


Regards,

Andy Y

Staff
Rank: #175

What version of the OutSystems platform are you using? What version of Service Studio?

Can you share an OML with a small repro of the issue?

Is the API in question publicly available? If so, can you post the endpoint URL?


Rank: #5558

i have the same issue, im trying to consume an API but it always results in "The underlying connection was closed: An unexpected error occurred on a send".

I've Tried using Postman and its working. so does anyone knows what is the solution ? i'm using Outsystems 11


mvp_badge
MVP
Rank: #17

Hi Andy,

Consuming a multipart form data REST API is not so straight forward to implement. Kilian Hekhuis actually wrote a great article about it.

I would suggest to read it:

https://www.outsystems.com/blog/posts/consuming-multipart-form-data-rest-method/

And a sample Forge application:

https://www.outsystems.com/forge/component-overview/4026/multipart-form-data

Learning by example many times help to get quicker results.

Hope the additional info and sample code will help you.

Regards,

Daniel

Rank: #2930

I am getting the same error. And I am not trying to use multipart for data, but a simple Get. Trying to consume a simple Rest, a call to a public server: https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/metadata

Calling this endpoint in a browser or with Postman gives the expected response, no error. Calling this endpoint from the Outsystems platform (11.9.1) gives me the same type of error as reported by Andy. No need to ask for an OML, it can be reproduced on the development platform in the Logic/Integrations/Rest/Consume Rest API  interface and simply using the endpoint URL mentioned above. See error message below.


Any suggestions? Thanks Denis.

The underlying connection was closed: An unexpected error occurred on a send.

[1] The underlying connection was closed: An unexpected error occurred on a send.
at System.Net.HttpWebRequest.GetResponse()
at sssantecure.CcEpicProduction.ActionGetMetadata(HeContext heContext, ICcEpicProductionCallbacks _callbacks, String inParamAccept, Int32 inParamProxy, String inParamEHR, STInstanceStructure& outParamResponse)

[2] Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)