How to make httpclient call from the client to the server using .net core
Hello Everyone,
I want to make some httpclient calls to the server using .net core. I would really appreciate if anyone can provide me any reference or an idea how to do it it will be really helpful.
Using .net framework it's not a problem, but using .net core I don't understand what will be the best way to go.
To be more specific about my question, I would generalize it: That is,
I want to make HttpClient calls to the server, to request for the api to the server and get the response back from the server in the form of http requests and response.
Thank You!
I look forward for your response.
Best regards,
Sandeep
Using .net framework it's not a problem, but using .net core I don't understand what will be the best way to go.
@SandeepApsingekar Whatever code you're using for .NET Framework should work. .NET Core has the same API surface area of HttpClient as Full Framework. Can you post your code sample from full framework that doesn't work with .NET Core?
Hi Priya,
Thank you so much for following up with me. I actually had a problem in retrieving the url in the async methods. Now, I figured out the way. I can share the code of .NET core which I'm working on right now. Following is the code where I'm accessing the uri:. HttpClient client = new HttpClient(); client.BaseAddress = new Uri("api url"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
Now, I'm calling this method in GetAsync using the required path.
Thank You! Regards, Sandeep
Now, I figured out the way.
Closing the issue.