3,165 questions
0
votes
0
answers
91
views
404/405 results using HttpClient in c# to upload/rename/delete files on a web server
I am migrating an oldish Windows desktop app from .NET framework 4.8 to .NET 9/MAUI. There are some loose plans for making the project multiplatform at some point (Android and Windows), but right now, ...
4
votes
1
answer
77
views
HttpClient.GetStreamAsync hangs when consuming .NET 10 Server-Sent Events from Blazor WebAssembly
I am experimenting with the new .NET 10 built-in Server Sent Events (Results.ServerSentEvents) on my ASP.NET Core Web API backend.
The backend endpoint works correctly:
The request arrives
The SSE ...
1
vote
1
answer
237
views
HttpIOException: The response ended prematurely
We migrated our .NET Framework application to .NET Core 8.0. Our system, which worked flawlessly with .NET Framework's HttpWebRequest gets an error as shown in the trace below when switching to the ...
0
votes
0
answers
99
views
How to send HTTP POST request with multipart/form-data with the form-data in initial request in .NET Framework?
I have to upload a file to an embedded device running an API.
First, I tried to write methods to do this in a test project. This works great:
private static async Task<HttpResponseMessage?> ...
0
votes
1
answer
72
views
Move HTTP request with cert file from nodeJs to .NET not working
I try to move a request with certificate from an old system made with NodeJS to a new system using .NET 8.0.
Running the .NET code, however, I always get the following error:
The SSL connection could ...
Best practices
0
votes
3
replies
70
views
Most efficient way to manage the lifecycle of HttpClient in many wrapper classes?
Our application is somewhat of a middleman that transforms data from numerous APIs. Initially to simplify things, we wrote a bunch of specific clients which wrap an instance of HttpClient created in ...
Best practices
2
votes
4
replies
89
views
How do I parse multipart content from an HttpResponseMessage?
I am using HttpClient in .NET 9 to get content that has a JSON part along with a base-64 encoded file. Reading the content as a string, I don't see a clear format that would ensure consistent parsing ...
0
votes
1
answer
197
views
C# Https call using HttpClient does work in Windows 7, but not in Windows 10
In Windows 7 32-bit, on .NET 4.6.1, this code works fine and the remote server is returning data:
using (HttpClient client = new HttpClient())
{
client.Timeout = TimeSpan.FromSeconds(3);
...
3
votes
2
answers
227
views
How to make system proxy settings apply to HttpClient.GetAsync() without restarting Windows?
We use the following function to test internet connectivity every 5 seconds. But in some part of the world, this function always returns false. Now, the problem is we can set a proxy server in Windows ...
1
vote
0
answers
80
views
Android HttpClient "Socket closed" error on slow connections, but server successfully processes request
I'm working on a .NET MAUI Android app that sends order data to a Web API using HttpClient. On normal Wi-Fi connections everything works fine, but when I throttle the network speed to around 56 kbps (...
1
vote
0
answers
66
views
HttpClient OAuth "No user found matching username"
I'm working on a console application to automatically interact with an API that needs and OAuth authorized user with a specific set of claims. If I use a browser to log in with a username and password ...
6
votes
3
answers
196
views
.NET IHttpClientFactory + Microsoft Resilience retry: same HttpRequestMessage resent, delegating handler not re-running?
I have an HttpClient built with IHttpClientFactory and Microsoft.Extensions.Http.Resilience retry on 401. Pipeline:
Primary: HttpClientHandler (AllowAutoRedirect = false)
Delegating: ....
2
votes
1
answer
145
views
Why am I getting a different HTTP response for a seemingly same request between curl, C# HttpClient Win10 and C# HttpClient Win11
I'm trying to download a webpage from a specific website (Bandcamp). I'm getting different results although the request seems the same:
On Windows 10, using a HttpClient in C#: I'm getting "...
1
vote
1
answer
116
views
Set-Cookie header disappears after some time when using HttpClient with DelegatingHandler in ASP.NET Core
I have a .NET Core project with two layers: an API layer and a UI layer, both in the same solution. The UI layer is built with ASP.NET Core MVC, where controllers call services, and the services use ...
4
votes
1
answer
189
views
Can't listen to 'http://127.0.0.100:50001/' with HttpListener on my machine, even though the port does not appear to be in use
My HttpListener for some reason can't listen to prefix http://127.0.0.100:50001/, getting an error
Unhandled exception. System.Net.HttpListenerException (32): The process cannot access the file ...
1
vote
0
answers
53
views
.NET HttpClient: How to read multiple responses from one request? [duplicate]
The http spec allows multiple responses per http request:
A single request can have multiple associated responses: zero or more "interim" (non-final) responses with status codes in the &...
1
vote
1
answer
102
views
Interaction and communication between C# classes
I have an API service class that implements HttpClient to connect to my API, I have a user list model, and I have a View Model using the Community Toolkit MVVM approach. I would like to understand how ...
1
vote
1
answer
106
views
Binding a ViewModel to data from an API
I have a problem because I'm relatively new to this and I'm trying to learn and do things at the same time, and I'm not sure if I'm doing it correctly. I need to get data from my API in the view model ...
1
vote
1
answer
153
views
How to handle certificate revocation behind a firewall which blocks revocation checks
I'm using a .NET HttpClient to connect to a server over HTTPS. For best practice, I want to check the certificate hasn't been revoked, by setting HttpClientHandler.CheckCertificateRevocationList = ...
0
votes
0
answers
72
views
Not receiving any response with HttpClient, despite one being sent
The calling application calls the auth endpoint of an API to receive a token. The API will, on successful authentication, return a JWT bearer token for the calling application to then use in ...
0
votes
0
answers
44
views
App Service sandbox blocks all forms of dynamic client certificate usage in HttpClient
I’m trying to make TLS calls using HttpClient in an Azure App Service (Windows) with a certificate that is dynamically loaded at runtime (e.g., from blob storage or Key Vault as a byte array).
A third-...
2
votes
1
answer
83
views
How to correctly create middleware extensions?
I am refactoring my code and moving some classes to an external assembly. In my projects I use Refit and currently I set it up like this in Startup:
services.AddHttpClient();
services.AddRefitClient&...
4
votes
1
answer
1k
views
ServicePointManager is obsolete in .NET 9 — how to configure SecurityProtocol (e.g., TLS 1.2/1.3) with HttpClient?
Working on project, we have upgraded to .Net 9. I am getting a warning in Program.cs at below line:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;
...
0
votes
0
answers
128
views
Refit client returns cached responses despite no-cache headers and HttpMessageHandler
I'm experiencing a caching issue with Refit when calling Keycloak Admin API endpoints. Despite setting various no-cache headers and implementing a custom HttpMessageHandler, I'm still getting cached ...
1
vote
0
answers
49
views
"ssl connection could not be established" when try to call API from local IIS
I try to call an azure hosted API from local IIS, but keep getting the error:
ssl connection could not be established. authentication failed. The message received was unexpected or badly formatted
...
1
vote
0
answers
207
views
Right way to do HttpClient that can be injected and used in Blazor server
Currently, I have this configuration for http client that I can use and inject when needed, wrapped with JWT authentication to hit some API address that has multiple end points:
builder.Services....
0
votes
0
answers
63
views
HttpClient fails to connect to specific HTTPS site in Docker container, works locally
I'm encountering an issue where HttpClient fails to establish an HTTPS connection to a specific site (https://www.csgt.vn) when running inside a Docker container.
This is the minimal code:
var client =...
3
votes
2
answers
219
views
HttpClient - Request times out but I don't understand why
I have put together an example code that shows what I mean. I am trying to download two different datasheets, one from TI, the other from ST. Both exist and I can download them using any browser (even ...
2
votes
1
answer
358
views
Forcing C# HttpClient to resolve host via DNS every time
My use case is I have a series of services running via Docker Compose, each using the deploy.replicas attribute to get some n number of instances.
services:
myservice:
image: ...
ports:
...
2
votes
0
answers
51
views
UWP HttpClient GetAsync waits forever depending on computer
Why might this Windows.Web.Http.HttpClient instance work on one computer and not another?
I've found these three posts that talk about why Windows.Web.Http.HttpClient.GetAsync might not ever return ...
4
votes
1
answer
187
views
Cannot replicate successful Postman request with HttpClient
I want to download a web page using HttpClient in .NET, but I receive a 403 Forbidden response, whereas using Postman with the same request parameters, I get a 200 OK. Here's my C# code:
var client = ...
0
votes
1
answer
253
views
Avoid blocking on NSwag generated client
The code generated by NSwag allows the consumer to pass a CancellationToken, which it uses on the call to HttpClient.SendAsync, but it doesn't use on the downstream call to response.Content....
2
votes
1
answer
159
views
How can I mitigate "Only 'http' and 'https' schemes are allowed." ArgumentException in System.Net.HttpClient.PutAsync?
I am using System.Net.HttpClient in a client application and needing to PUT to a third party service I have no control over. The third party service gives responses such as:
Date: Wed, 04 Jun 2025 20:...
0
votes
1
answer
104
views
How provide bearer token (or pass any parameter) at runtime when configuring IHttpClientFactory
We are using the new Keyed DI support in IHttpClientFactory in .NET 9, with different clients defined for each API endpoint. Defining static values, such as the base URL is straight forward, but we ...
0
votes
0
answers
81
views
Correct use of HttpClient for a VSTO addin
I recently updated and migrated my backend from SOAP WCF to a REST API (C#). This backend is utilized by an Outlook add-in (desktop version) to save documents, including emails and attachments, to a ...
0
votes
2
answers
62
views
Get data received before HttpClient request is cancelled
I'm trying execute an HTTP request to receive some data (for example as a stream), but with ability to cancel this request at any time. I've read about CancellationToken and use it for cancel request (...
0
votes
1
answer
271
views
Define custom headers using .NET 6 OpenAI SDK
Technical details
Client applications are using .NET 6
Client applications are using the OpenAIClient class from the official OpenAI nuget library
There is an inhouse cluster of LLM servers with ...
0
votes
2
answers
150
views
Add individual certificate to HttpClient created via HttpClientFactory
I do have a .NET 8.0 web application using HttpClient to send requests to different vendors. To get the HttpClient objects, I'm using the IHttpClientFactory interface installed via AddHttpClient ...
1
vote
0
answers
115
views
HttpClient cold start and idle timeout problem
ASP.NET Core 8 Web API service with can execute another service. I read this:
https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
https://byterot.blogspot.com/2016/07/singleton-...
0
votes
2
answers
118
views
Can we configure HttpClientHandler in IHttpClientFactory DI implentation?
I'm getting multiple intermittent 'Socket Exception' error while using httpclient(IHttpClientFactory DI Implementation) .
As per MS documentation,
A new HttpClient instance is returned each time ...
0
votes
0
answers
70
views
ASP.Net Core 9 HttpClient.PostAsync fails to hit controller endpoint
HttpClient.PostAync does not reach controller endpoint at all. GetAsync and DeleteAsync are OK.
Program.cs:
builder.Services.AddControllersWithViews();
app.MapControllers();
Controller:
[Route("...
-1
votes
2
answers
61
views
Dynamically setting the IHttpClientFactory timeout
What is the best way to dynamically change the timeout of an application if we are using IHttpClientFactory? I don't mean I want a different timeout for different addresses or endpoints - I mean all ...
0
votes
1
answer
106
views
.NET 7 HttpClient, HttpResponseMessage.Content.ReadAsStreamAsync - memory trouble
The environment is a .net (.net7.0) service, running in a Linux-based Docker container. It needs to communicate with an external REST API, download a large-ish zipped file, unzip it and upload to an ...
5
votes
0
answers
331
views
System.Net.Http.HttpRequestException: 'Received an invalid status line: 'HTTP/2 200 '.'
here is my code:
using HttpClient client = new HttpClient();
try
{
HttpResponseMessage response = await client.GetAsync("http://131.189.89.86:11920/SetupWizard.aspx/yNMgLvRtUj");
}
...
0
votes
2
answers
223
views
Polly in C# is retrying the request, even though HttpClient isn't timing out and there are no errors
I have an API client that calls an API hosted in Kubernetes and using kong for gateway API, which is built using ASP.NET 6.
We've also configured a Polly policy to retry the request if it receives an ...
3
votes
1
answer
133
views
Downloading a file from another website with Azure Functions
I am creating an Azure function that will download a file from a website and upload to the Blob store. I have the Azure function working locally but it does not work when deployed. I can't see ...
0
votes
0
answers
49
views
Is there an alternative HttpClient handler for .NET Framework 4.5 that does not depend on Windows for HTTPS?
I have a legacy project running on .NET Framework 4.5, and we recently encountered issues because HttpClient relies on Windows for HTTPS connections.
Is there an alternative HttpMessageHandler that ...
1
vote
1
answer
76
views
Preventing existing polly policy from being invoked for certain results
I have a predefined IAsyncPolicy<HttpResponseMessage> policy coming from an external assembly.
I want to apply this policy to a Http Client, BUT I want to exclude one of the cases this policy ...
3
votes
1
answer
72
views
Reproduce Invoke-WebRequest behaviour in C# [duplicate]
I've exported a request from my Chrome browser using "Copy as PowerShell", trimmed it to a minimum and the script runs successfully:
Invoke-WebRequest -Uri "https://www.sec.gov/data-...
1
vote
0
answers
83
views
Why is there a 15-second delay when using HttpClient to call a third-party API, but it works fine with curl? [duplicate]
I have deployed a feature in my production environment where I need to call a third-party API using HttpClient in .NET. However, I've noticed that there is a consistent 15-second delay when calling ...