3,171 questions
0
votes
0
answers
60
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
0
answers
56
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 ...
-3
votes
0
answers
74
views
HttpClient and headers
I have a legacy .NET 4.8 framework project.
I have tried to get these headers:
Accept-Encoding
CacheControl
sent to my endpoint.
But looking with Fiddler, they are not sent, even if I explicitly set ...
Best practices
0
votes
3
replies
59
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
74
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
182
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
163
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
59
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
65
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 ...
5
votes
3
answers
156
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
121
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
105
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
159
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 &...
0
votes
0
answers
52
views
.NET MAUI for Android in connection API localhost [duplicate]
I have a problem, I get this error
[0:] Connection failure: ERROR {0}
when using a connection in a .NET MAUI project for Android. I applied the Microsoft instruction for the case when the API works ...
1
vote
1
answer
99
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
101
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
107
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
61
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
35
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
80
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
643
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
103
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
46
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
141
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
60
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
201
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
279
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
46
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
167
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
202
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
140
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
96
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
76
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
60
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
216
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
116
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
107
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
105
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
65
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
47
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
100
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
307
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
163
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
125
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
36
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
68
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
65
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
81
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 ...
0
votes
0
answers
69
views
How to retrieve access token and use for subsequent requests?
I am creating an ASP.NET Core Web API that is intended to work as a middle ground between several third party API's and a first-party web application to sync data between the third parties and my main ...