How to add parameters when using HttpClient to send request?
I have a problem with my target API; it takes two parameters, and I need to figure out how to add two parameters to my request. Would anyone please explain how I can make that call with HttpClient?
My target API's signature, which I am going to call, looks like:
//It takes post call only
public string Authentication(string UN, string AP)
This is in my startup.cs:
services.AddHttpClient("Authentication", APIHttpClient =>
{
APIHttpClient.BaseAddress = new Uri("Target API address");
}).ConfigurePrimaryHttpMessageHandler(() =>
new HttpClientHandler
{
UseCookies = false
}
);
in my class:
public class MyService
{
private IHttpClientFactory _clientFactory;
public MyService(IHttpClientFactory httpClientFactory){
_clientFactory = httpClientFactory;
}
public MyMethod(){
HttpClient httpClient
_httpClientFactory.CreateClient("Authentication");
// I need to add parameter here
}
}
Hopefully, someone can show me how to code it, Thank you!
You could send request with parameters like below if the api is POST request:
The API:
If the api is GET request: