Questions tagged [dotnet-httpclient]
Refers to the System.Net.Http.HttpClient library which is part of the HttpClient package on NuGet, or the .NET 4.5 library.
2,501
questions
0
votes
0
answers
17
views
GetAsync API in c# is not working when parameter are added dynamically
Uri URL = new Uri($"https://authenticom.azure-api.net/dv-delivery/v1/delivery/?requestId={requestId}&pageSize={pageSize}")
HttpResponseMessage response = client.GetAsync(URL).Result;
...
0
votes
1
answer
33
views
When I using a thread to run HttpClient.GetAsync(...) and it never returns response
I using a C# Console app to test Httpclient GetSync().
When code run in getsync() and just close done my app.I need to get the response result.
Is the thread and task await to conflict or the thread ...
0
votes
1
answer
33
views
Blazor WASM Http call is not hitting some API endpoints. Receiving index.html instead
I have a Blazor WASM page that need to make a call to get some data from an API. The Blazor app is ASPNetCore hosted, and the hosting app contains the API.
Some of my endpoints work, but some calls ...
2
votes
2
answers
65
views
.NET 6 Port exhaustion when using HttpClient in factory class
I've been experiencing some port exhaustion recently, and I recently stumbled across this video by Nick Chapsas where he talks about how misusing HttpClient can lead to some of the same issues that I'...
0
votes
1
answer
16
views
RestSharp upload image with imagesource. (Image exist only as Variable)
How to upload a Image with RestSharp without using a local path.
Image exists only in a Image Variable.
All i found was with a string as path, but this is not the way i want to go.
Or is it possible ...
0
votes
0
answers
10
views
Getting Some Randam ID when Sending a file using MultipartContent() and HttpClient
I am trying to send a file via an API. I was able to receive the file in my API, but for some reason I am seeing random ID(could be content id) when I read the content in my API.
Previously I was ...
0
votes
1
answer
35
views
How does IHttpClientFactory.CreateClient(customClient) creates the async definition of an HttpClient?
I've stumbled in a peculiar case where the named HttpClient that I want to build is run with an async function, like this:
services.AddHttpClient("customClient", async (serviceProvider, ...
0
votes
1
answer
31
views
HttpClient 401 Unauthorized - How to authenticate IIS website to another IIS website
I have this well known 401 Unauthorized error. My scenario is that website A needs to call HTTP request (GET) to website B. Both websites runs on the same IIS server under different application pools (...
-1
votes
2
answers
39
views
How to mock HttpClient.GetFromJsonAsync?
I've got some code that calls HttpClient's GetFromJsonAsync however I'm struggling to mock the method call and was wondering how can I do this?
C# code:
public class Client : IClient
{
private ...
0
votes
0
answers
51
views
How to configure an httpclient using Autofac and Polly in old 4.6.1 .Net framework
There is a legacy app that uses an httpClient to interact with Web API backend.
I would like to configure several httpClients in Autofac DI container. The configuration must include timeouts, Polly (...
0
votes
0
answers
72
views
Add HTTP message handler in .NET 6 REST Service
I have implemented a Message Handler (DelegatingHandler), here is my code:
public class BongLogClient : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(...
0
votes
1
answer
61
views
100 seconds timeout when accessing Microsoft Graph with HttpClient - but not with curl - inside Docker container
I am running a .NET 6 / ASP.NET Core application inside a Docker container on a Raspberry Pi.
Dockerfile to see .NET setup
This application is accessing Outlook and OneDrive using the Microsoft Graph ...
0
votes
2
answers
42
views
Add Jwt token in header for every Http call using the concept of `HttpInterceptor` From angular for asp.net core web api [duplicate]
Is there any way to implement an interceptor so that I can call a microservice api from another microservices where all the http call will be intercepted & added jwt token in the header? So that, ...
1
vote
1
answer
58
views
C# SSL exception on Windows 7
var httpClientHandler = new HttpClientHandler
{
SslProtocols = SslProtocols.Tls12,
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; },
};
var ...
0
votes
0
answers
23
views
Request timed out Error while hitting the api
While Hitting the api i am getting this Exception A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because ...
1
vote
0
answers
58
views
.NET API HttpRequestMessage not setting Header Authorization
We have an front-end application that authenticates through a third party.
We also have an API with an endpoint that receives requests from this front-end application.
To validate the token sent from ...
1
vote
0
answers
47
views
Multiple implementation of HttpClient. One with HttpClientHandler and another without it [closed]
There is no use of IHttpClientFactory since there is a no way to configure HttpClientHandler with credentials because they are not available at the time of configuring HttpClient in Program.cs
And ...
-1
votes
1
answer
84
views
.NET Core HttpClient exception
I am using .NET 6 to develop the core Web API, I have a abstract class AdminApiClient inherit ApiClientBase class like below:
public abstract class AdminApiClient : ApiClientBase
{
protected ...
0
votes
0
answers
17
views
Can't add file with httpClient with C# and get it with nodejs and multer
I am using a server with nodejs and writing file with multer. While using with kotlin I can easily send file with the following code with retrofit:
val reqFile: RequestBody = file.asRequestBody("...
-2
votes
1
answer
39
views
DeserializeObject Newtonsoft fail when try to deserialize HttpResponseMessage obtained from HttpClient
The following code to make deserialization is producing the following error when executed.
The purpose is get the result coming from httpClient of .Net(client) and transform it to make a comparison in ...
0
votes
0
answers
19
views
Is there any way, how to get the redirect uri?
Background:
Let's have a WebAssembly (wasm) originating from .net code.
This wasm uses HttpClient and HttpClientHandler to access a backend API at https://api.uri.
The actual backend API location ...
0
votes
0
answers
48
views
HttpClient PatchAsync fails unless I put delay before request
I am unsure if this is a bug, or if I'm doing something wrong here. This has to be one of the weirdest bugs that I've ever come across.
I am injecting an HTTPClient into my service and doing a ...
-1
votes
0
answers
32
views
Downloading Excel is giving network issue on chrome/Edge browser
I am trying to download the excel report with the below code snippet and it works on local but whne deployed to server gives me network failed error
public ExportFile(string rptextn,string RptName )
{...
0
votes
0
answers
31
views
Automatically trigger API call when change in MongoDB
I am currently working in a mobile application (Front End : Flutter, Back End : Dot net, DB : Mongo Db), I want to achieve one functionality that is whenever there is a change in DB an API request ...
1
vote
2
answers
104
views
HttpClient.SendAsync sending wrong Content-Type
HttpClient httpClient = new HttpClient();
MyRequest request = new MyRequest (data);
var content = new StringContent(System.Text.Json.JsonSerializer.Serialize(request), System.Text....
0
votes
0
answers
48
views
Lambda expression results in error CS1643: Not all code paths return a value in lambda expression of type 'Func<HttpClient, TRepository>'
The following code results in the error message:
error CS1643: Not all code paths return a value in lambda expression of type 'Func<HttpClient, TRepository>'
Here is the class:
public class ...
1
vote
2
answers
127
views
Polly Retries Doesn't Close Existing HttpClient Call
I'm using Polly to handle some scenarios like request throttled and timeouts.
The policies were added directly in the Startup.cs which would be like this :
var retries = //applying the retries, let ...
0
votes
0
answers
66
views
.Net Core 6- A connection attempt failed because the connected party did not properly respond after a period of time
I have a web api, its calling another api for getting user info.
But sometimes we are getting this timeout error.
Its happening in QA. not able to reproduce in local.
That third party server is not ...
0
votes
0
answers
66
views
HttpClient GetAsync returns 404 on local Web Service
I got two Visual Studio Instances, one with an ASP.NET .NET6 Application, and another one with a .NET Framework 4.8 console application, from which I want to call the web app.
Whenever I call the web ...
3
votes
2
answers
85
views
Inconsistent outcome when trying to fetch all items from a paginated url
I am having the issue of fetching all forms currently hosted in hubspot.
I tried with a simple for loop where I made one request at the time, and fetched one form at a time, which worked, but was very ...
1
vote
1
answer
52
views
HttpClient.GetAsync() selectively ignoring query parameter
I have a very simple method for querying a webpage and parsing the results. The body of the response isn't the problem, the problem is that the request generated by the GetAsync(string) or GetAsync(...
0
votes
1
answer
27
views
.NET HttpClient Image Upload to PlantNet API
I am trying to make a Request to the PlantNet API via .NET HttpClient. I have a FileStream and I am using the StreamContent and when I look via debugger at the content before it is sent it's looking ...
1
vote
1
answer
60
views
HttpClient.PostAsync() method is hanging forever in C# xUnt test
I have 600 functional xUnit tests and each of the test is calling a httpClient.GetAsync(apiUrl) and httpClient.PostAsync(apiUrl, data) methods in the middle of the test which will call some external ...
0
votes
0
answers
46
views
"The socket is not connected" Error resuming Xamarin app
When my app resumes from a minimized/background state I occasionally get this error
System.Net.Http
ConnectHelper.EstablishSslConnectionAsyncCore (System.IO.Stream stream, System.Net.Security....
1
vote
3
answers
33
views
This HttpRequestMessage Headers are assignable even that they are { get; } only
Why do I get about this assignment into Headers this error
var request = new HttpRequestMessage()
{
Headers = default
};
Property or indexer 'property' cannot be assigned to -- it is read only
...
3
votes
0
answers
100
views
Memory leaks in Http client in .net framework 4.5
I have a windows service application built with .Net framework 4.5. This service when kept running for a longer duration keeps on accumulating memory and slowly gradually it takes up to 100-200MB.
The ...
2
votes
1
answer
92
views
C# HttpClient gets new SessionID every request
The title explains it mostly. I have declared my HttpClient, HttpClientHandler, and CookieContainer as class variables.
private HttpClient client;
private HttpClientHandler handler;
private ...
0
votes
0
answers
48
views
HTTP Client Post Async Always Produces Task cancelled in web API project While it is working in console APP c#
I have created two projects, one is console application another is WEB API in c#, In this i have called a API using HTTPClient using postAsync method. It is working fine in Console Application (.net ...
0
votes
0
answers
91
views
Why does .NET Core HttpClient or WebClient take so much longer than Python
I am trying to retrieve content from a URL, I have tried .NET Core's HttpClient and WebClient, both of which take ~10 seconds to load this specific website.
However, when I use Python's urllib.request ...
0
votes
1
answer
61
views
HttpClient after internet reconnected "The remote name could not be resolved"
Context
I have a laptop in a corporate network using a proxy.
When I use the HTTP client (.NET Framework 4.8) in an application it works fine.
When I unplug internet, I get The remote name could not ...
1
vote
1
answer
109
views
How to enable CORS in Blazor Static Web App?
I have tried every other ways to set Access-Control-Allow-Origin : * in my Blazor Static Web App.
I follow this documentation Configure Azure Static Web Apps first to set globalHeaders. It isn't ...
0
votes
0
answers
30
views
What happens to connection when a httpclient request times out?
I'm calling an API which has a rate limit on number of concurrent requests (e.g. 10).
Problem is when a request times out. From my end the request is complete and I can send a new one. But the server ...
0
votes
0
answers
38
views
Salesforce Account Creation via REST POST API Is Always Failing With Error "Bad Request" Via C#
I'm trying to write a simple console based application with the help from C# to create Salesforce standard objects like Accounts, Contacts, Leads etc. As a starting point I tried to create account ...
0
votes
1
answer
49
views
Can't import System.Net.Http on VB.Net page
I'm trying to use HttpClient on a VB.NET page (Windows Server 2019 IIS 10), but getting BC30002 error. Tracing the error in IIS, I see warning BC40056 (Namespace not found) on line:
Imports System.Net....
0
votes
1
answer
74
views
Facing timeout issue in Azure Durable function
I'm using Azure Durable function to perform some batch processing operations. Something in the lines of Read, Process, Notify
There was a limit of 10, to the number of times these operations were ...
0
votes
0
answers
34
views
Long HttpClient execution time after Thread.Sleep(80000+)
If the pause between two requests is less than 80 seconds, request execution time about 400-700 ms. But if the pause is more than 80 seconds, execution time about 1000-1500 (like first request). Why?
...
0
votes
0
answers
15
views
Request forwarding works with catch all route but not otherwise
We have a API built with dotnet core 3.1 and are trying to forward some requests to a different API. Lets say all calls to the path todos/** should be forwarded. When i use a catchall route this works ...
1
vote
1
answer
131
views
Why GetFromJsonAsync can't parse the JSON but ReadFromJsonAsync can parse the same JSON response?
I'm using HttpClient to send requests to my API project, the problem is that the GetFromJsonAsync method fails to parse the response JSON, but if I first get the response using the GetAsync method, ...
0
votes
0
answers
62
views
How do I acquire the serialized URL from HttpResponseMessage?
Is there a way to acquire the fully serialized URL address from a response?
Given the request below, I'd like to acquire the following string: http://192.168.0.72:8080/manufacturer if possible. This ...
0
votes
0
answers
43
views
how to use HttpClient in DI
This is a demo
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddHttpClient<MyClient>();
var app = builder.Build();
using (var scope1 = ...