I have the following code :
String url = // a valid url String requestXml = File.ReadAllText(filePath);//opens file , reads all text and closes it byte[] bytes =
Adding this line of code solved the problem for me:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
This was taken from: https://our.umbraco.com/forum/using-umbraco-and-getting-started/74628-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-send