title: HttpClient Posting to api, getting System.IO.IOException: Authentication failed because the remote party has closed the transport stream
body: <p>I am successfully calling a service using the VS RestClient addin (changes made to protect secrets)</p>
  <pre><code>POST https://zzz-apis-xyz.com/abc/abc-data/v1/abcbusinessdata HTTP/1.1
  X-Special-Client-Id: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
  X-Special-Client-Secret: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
  accept: application/json 
  clientID: cccccc 
  content-type: application/json 
  abcDistributedKey: ---guid--- 
  systemName: chicken
  
  {
      &quot;business&quot;: &quot;Hilton&quot;,
      &quot;address&quot;: &quot;7930 Jones Branch Drive&quot;,
      &quot;city&quot;: &quot;McLean&quot;,
      &quot;state&quot;: &quot;VA&quot;,
      &quot;postalCode&quot;: &quot;22102&quot;
  }
  </code></pre>
  <p>I am trying to use the following code to post this to the api using the following C#</p>
  <pre><code>var request = new ApiRequest {
    business = &quot;Hilton Hotels&quot;,
      address = &quot;7930 Jones Branch Drive&quot;,
      city = &quot;McLean&quot;,
      state = &quot;VA&quot;,
      postalCode = &quot;22102&quot;,
  };
  
  var requestJson = JsonConvert.SerializeObject(request);
  
  var httpRequestMessage = new HttpRequestMessage {
    Method = HttpMethod.Post,
      RequestUri = new Uri(&quot;https://zzz-apis-xyz.com/abc/abc-data/v1/abcbusinessdata&quot;),
      Headers = {
        {
          &quot;X-Special-Client-Id&quot;,
          &quot;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&quot;
        },
        {
          &quot;X-Special-Client-Secret&quot;,
          &quot;yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy&quot;
        },
        {
          &quot;clientID&quot;,
          &quot;cccccc&quot;
        },
        {
          &quot;abcDistributedKey&quot;,
          Guid.NewGuid().ToString()
        },
        {
          &quot;systemName&quot;,
          &quot;GLASS&quot;
        },
  
      },
      Content = new StringContent(requestJson, Encoding.UTF8, &quot;application/json&quot;),
  
  };
  
  using(var client = new HttpClient(new HttpClientHandler {
    UseDefaultCredentials = true
  })) {
    client.BaseAddress = new Uri(&quot;https://zzz-apis-xyz.com/&quot;);
  
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(&quot;application/json&quot;));
  
    try {
      var response = await client.SendAsync(httpRequestMessage);
      var stringResponse = await response.Content.ReadAsStringAsync();
  
    } catch (Exception e) {
      Console.WriteLine(e);
      throw;
    }
  }
  }
  </code></pre>
  <p>This code worked on two days ago but today fails with the error (another dev is also experiencing this) (NOTE: vscode and this C# code are both running on the same machine):</p>
  <blockquote>
  <p>System.Net.Http.HttpRequestException: An error occurred while sending
  the request. ---&gt; System.Net.WebException: The underlying connection
  was closed: An unexpected error occurred on a send. ---&gt;
  System.IO.IOException: Authentication failed because the remote party
  has closed the transport stream.
  at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)    at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext&amp; context)    at
  System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult
  ar)
  --- End of inner exception stack trace ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
  at
  ThirdPartyData.WebApi.Tests.ServiceTest.d__1.MoveNext()
  in
  ccccccccccccccc :line
  128
  --- End of stack trace from previous location where exception was thrown ---    at
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)    at
  Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action
  action)</p>
  <p>System.Net.Http.HttpRequestException: An error occurred while sending
  the request. ---&gt; System.Net.WebException: The underlying connection
  was closed: An unexpected error occurred on a send. ---&gt;
  System.IO.IOException: Authentication failed because the remote party
  has closed the transport stream.    at
  System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)    at
  System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)    ---
  End of inner exception stack trace ---    at
  System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult
  asyncResult, TransportContext&amp; context)    at
  System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult
  ar)    --- End of inner exception stack trace ---    at
  System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
  task)    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()</p>
  </blockquote>