So I have BC 27.1 running in a local Docker container. And I have a Visual Studio 2022 ASP.NET Core web app also running. The issue involves a BC codeunit procedure that is making the API request. It returns back NavHttpClient Error Code 0. This is a simple GET request to the localhost that's running a debug of the ASP.NET Core web app. No authorization. No content body. When debugging on the VS Code end for the AL codeunit procedure, I can Ctrl+Click the request URL and it comes up just fine in a web browser. And using the same request URL in a Postman GET request, it comes back fine as well.
I'll paste my AL procedure code below. Along with another test procedure to a third-party test web service that works fine. It's just my own localhost web app that's failing. Perhaps this is due to server certificate validation failing? I tried disabling that feature in my code, although with BC 27.1, I thought that this couldn't be disabled. I even tried replacing the request URL with the http alternative to https and that runs into the same issue.
Any advice? I have enabled HttpClient calls in my extension setup. And the other test procedure works fine.
procedure MyApiCall(): Text // This fails.
var
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
Content: HttpContent;
Headers: HttpHeaders;
ResponseText: Text;
RequestUrl: Text;
begin
RequestUrl := 'https://localhost:7043/test';
Request.SetRequestUri(RequestUrl);
Request.Method('GET');
Request.GetHeaders(Headers);
Headers.Clear();
Headers.Add('Accept', 'application/json');
Headers.Add('Connection', 'keep-alive');
Headers.Add('Accept-Encoding', 'gzip, deflate, br');
Headers.Add('User-Agent', 'Business-Central-365');
Client.UseServerCertificateValidation(false);
Client.Send(Request, Response);
Response.Content().ReadAs(ResponseText);
exit(ResponseText);
end;
procedure TestApiRequest(): Text // This works.
var
Client: HttpClient;
RequestHeaders: HttpHeaders;
RequestContent: HttpContent;
ResponseMessage: HttpResponseMessage;
RequestMessage: HttpRequestMessage;
ResponseText: Text;
RequestUrl: Text;
begin
RequestUrl := 'https://api.restful-api.dev/objects';
RequestHeaders := Client.DefaultRequestHeaders();
RequestContent.GetHeaders(RequestHeaders);
Client.Get(RequestUrl, ResponseMessage);
ResponseMessage.Content().ReadAs(ResponseText);
exit(ResponseText);
end;