Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET 4.5 HttpClient PUT or POST over SSL always fails
    primarykey
    data
    text
    <p>I am having a terrible time troubleshooting this issue. I'm also having a terrible time reproducing it consistently from one application to another.</p> <p>Under certain circumstances, which I cannot seem to identify, making <code>PUT</code> and <code>POST</code> calls using the <code>HttpClient</code> results in the following exception.</p> <blockquote> <p>An error occurred while sending the request.</p> <p>Inner Exception:<br> The underlying connection was closed: An unexpected error occurred on a send.</p> <p>Inner Exception:<br/> This operation cannot be performed on a completed asynchronous result object.</p> </blockquote> <p>Everything seems to work with HTTP, this only happens on HTTPS.</p> <p>Certificates are valid, but I have tried setting the <code>ServicePointManager.ServerCertificateValidationCallback += (s, c, ch, es) => true;</code></p> <p>I have tried setting <code>client.DefaultRequestHeaders.ExpectContinue = false;</code></p> <p>I have tried, what seems like a million, other things ranging from headers, authentication, etc.</p> <p>Does anyone have any idea what else I can check, try, etc?</p> <p>Code snippet:</p> <pre><code>// this is my registration in my IoC container... var handler = new HttpClientHandler { UseDefaultCredentials = true, Credentials = CredentialCache.DefaultNetworkCredentials, }; var client = HttpClientFactory.Create(handler); client.BaseAddress = new Uri(Properties.Settings.Default.BaseUrl); client.DefaultRequestHeaders.Add("X-CustomHeader", "value"); // _client is constructor injected into my class... var response = await _client.PutAsJsonAsync("api/resource/" + id, model).ConfigureAwait(false); response.EnsureSuccessStatusCode(); // &lt;-- never executes... </code></pre> <p><strong>UPDATE:</strong></p> <p>If I take off the <code>ConfigureAwait(false)</code> it works fine.</p> <p>Note, this is a WPF app, specifically, this is a Visual Studio extension. However, I do have an ASP.NET MVC 4 application with the exact same problem, and that application does not call <code>ConfigureAwait(false)</code> at all...</p> <p><strong>UPDATE 2:</strong></p> <p>I updated the code snippet to include the instantiation of the <code>HttpClient</code> class. The only thing that is not included in the code snippet is the model type and declaration. It should be irrelevant, as it is a serializable class with all auto properties with no complex types.</p> <p><strong>UPDATE 3:</strong></p> <p>I don't know if this is relevant, but I have found a few things which look weird to me.</p> <p>When executing the above code, in Fiddler, I get a <code>401</code> on the <code>POST</code>, followed by 2 <code>CONNECT</code>'s which result in the following HTTP responses:</p> <blockquote> <p>HTTP/1.1 200 Connection Established<br> Connection: close</p> </blockquote> <p><strong>UPDATE 4:</strong></p> <p>I changed my IoC registration code to be this:</p> <pre><code>var handler = new HttpClientHandler { UseDefaultCredentials = true, Credentials = CredentialCache.DefaultCredentials, }; var client = HttpClientFactory.Create(handler); client.BaseAddress = new Uri(Properties.Settings.Default.BaseUrl); client.DefaultRequestHeaders.Add("X-CustomHeader", "value"); </code></pre> <p>and now it fails, but when I open Fiddler and let it decrypt traffic ... it works!</p> <p><strong>UPDATE 5:</strong></p> <p>I believe this must be a server issue, or a cert issue. Any tips on what to check from here would be greatly appreciated. Certs are valid and issued from a trusted CA.</p> <p><strong>UPDATE 6:</strong></p> <p>More debugging and troubleshooting. The exception occurs before the <code>ServicePointManager</code> <code>CertificateValidationCallback</code> is invoked.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload