Hi @Aamiz ,
You could use the IHttpClientFactory I mentioned above (I gave the link in the previous reply.).
- Use the Named clients method of IHttpClientFactory.
- Click on the link to view the detailed code, or you can view the code I copied from the link to the following.
Configuration for a named HttpClient can be specified during registration in Startup.ConfigureServices
services.AddHttpClient("myapi", c =>
{
c.BaseAddress = new Uri("http://localhost:57025/api/");
});
To create a named client, pass its name into CreateClient
var request = new HttpRequestMessage(HttpMethod.Get,"Mypage");
var client = _clientFactory.CreateClient("myapi");
var response = await client.SendAsync(request);
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
YihuiSun