Reputation: 599
Below is the code, I have used to call the api. However, May I know how to pass http header
for example Get customer has a header [FromHeader] field.
string uri = "https://localhost:7290/customers"; var response = await _httpClient.GetAsync(uri);
Upvotes: 0
Views: 225
Reputation: 3847
HttpClient GetAsync()
is a shortcut for generating an instance of a HttpRequestMessage
set to perform a GET for the specified URI and passing it to the SendAsync()
method.
You can create your own request message instance and append additional details such as headers, then use the SendAsync()
method yourself.
var request = new HttpRequestMessage(HttpMethod.Get, uri);
request.Headers.Add("header", "value");
var response = await client.SendAsync(request);
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage?view=net-6.0
Upvotes: 1