The code in consumer side is:
public class CategoriesController : Controller
{
Uri baseAddress = new Uri("https://IP ADDRESS:5000/api/");
private readonly HttpClient _httpClient;
public CategoriesController()
{
_httpClient = new HttpClient();
_httpClient.BaseAddress = baseAddress;
}
[HttpGet]
public async Task<IActionResult> Index()
{
List<Category> categories = new List<Category>();
HttpResponseMessage response =
await _httpClient.GetAsync(_httpClient.BaseAddress + "categories");
if (response.IsSuccessStatusCode)
{
string data = await response.Content.ReadAsStringAsync();
categories = JsonConvert.DeserializeObject<List<Category>>(data);
}
return View();
}
}
Thanks in advance
I created an API in .net8, and I setup the CORS for any request, region and header. The "applicationUrl" inside the "launchSettings.json" is set to
"applicationUrl": "https://IP ADDRESS:5000;http://IP ADDRESS:5001" in the "https".
But in consuming app which is created by MVC .net core8, once requesting, I got two error as follow:
AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)
HttpRequestException: The SSL connection could not be established, see inner exception. System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, bool async, Stream stream, CancellationToken cancellationToken)