Async call with await in HttpClient never returns

Check out this answer to my question which seems to be very similar. Something to try: call ConfigureAwait(false) on the Task returned by GetStreamAsync(). E.g. var result = await httpClient.GetStreamAsync(“weeklyplan”) .ConfigureAwait(continueOnCapturedContext:false); Whether or not this is useful depends on how your code above is being called – in my case calling the async method using … Read more

Struggling trying to get cookie out of response with HttpClient in .net 4.5

To add cookies to a request, populate the cookie container before the request with CookieContainer.Add(uri, cookie). After the request is made the cookie container will automatically be populated with all the cookies from the response. You can then call GetCookies() to retreive them. CookieContainer cookies = new CookieContainer(); HttpClientHandler handler = new HttpClientHandler(); handler.CookieContainer = … Read more

How do I pass an object to HttpClient.PostAsync and serialize as a JSON body?

The straight up answer to your question is: No. The signature for the PostAsync method is as follows: public Task PostAsync(Uri requestUri, HttpContent content) So, while you can pass an object to PostAsync it must be of type HttpContent and your anonymous type does not meet that criteria. However, there are ways to accomplish what … Read more

How can I tell when HttpClient has timed out?

I am reproducing the same issue and it’s really annoying. I’ve found these useful: HttpClient – dealing with aggregate exceptions Bug in HttpClient.GetAsync should throw WebException, not TaskCanceledException Some code in case the links go nowhere: var c = new HttpClient(); c.Timeout = TimeSpan.FromMilliseconds(10); var cts = new CancellationTokenSource(); try { var x = await … Read more

Retrying HttpClient Unsuccessful Requests

Instead of implementing retry functionality that wraps the HttpClient, consider constructing the HttpClient with a HttpMessageHandler that performs the retry logic internally. For example: public class RetryHandler : DelegatingHandler { // Strongly consider limiting the number of retries – “retry forever” is // probably not the most user friendly way you could respond to “the … Read more

Add client certificate to .NET Core HttpClient

I ran a fresh install for my platform (Linux Mint 17.3) following these steps: .NET Tutorial – Hello World in 5 minutes. I created a new console application targeting the netcoreapp1.0 framework, was able to submit a client certificate; however, I did receive “SSL connect error” (CURLE_SSL_CONNECT_ERROR 35) while testing, even though I used a … Read more

Strange issue with System.Net.Http 4.2.0.0 not found

The problem you’re facing is related to Visual Studio, especially 2017 which is shipped with System.Net.Http v4.2.0.0. However, adopting the new way whereby any references should be done via NuGet, latest version of System.Net.Http which is 4.3.3 contains the dll version 4.1.1.2. The problem is that VS at build time and at run time as … Read more