# Underlying Connection was closed

**URL:** <http://forum.companieshouse.gov.uk/t/underlying-connection-was-closed/2795>\
**Category:** API Issues\
**Created:** [January 7, 2020, 3:30pm UTC](http://forum.companieshouse.gov.uk/t/underlying-connection-was-closed/2795 "2020-01-07T15:30:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ash](http://forum.companieshouse.gov.uk/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@ash](http://forum.companieshouse.gov.uk/u/ash)\
**Post date:** [January 8, 2020, 9:58am UTC](http://forum.companieshouse.gov.uk/t/underlying-connection-was-closed/2795/2 "2020-01-08T09:58:41Z")

</div>

Failing authorisation due to incorrect formatting and encoding of the authorisation header can cause that exception. Check if this helps: [Getting invalid authorization - #7 by csmith](https://forum.aws.chdev.org/t/getting-invalid-authorization/41/7)

Another possibility is the security protocal being used by the request. It’s been a while but in my own code I have commented out a couple of lines where I had to explicitly set the protocol because older versions of .NET defaulted to one that was not supported.

You could try playing around with that, check which protocol is being used before the request:

i As Integer = ServicePointManager.SecurityProtocol

And then try changing it to a different one and seeing if that fixes things

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.XXX

I think there might be a minimum level of .NET needed. I’m not an expert and it’s been a while. I had to trial and error it at the time, but now (with a newer version of .NET) it works by default for us.

---

_[View the full topic](http://forum.companieshouse.gov.uk/t/underlying-connection-was-closed/2795)._
