web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

Local BC Docker Container and Local VS ASP.NET Core API Endpoint Issue

(0) ShareShare
ReportReport
Posted on by 565
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;
I have the same question (0)
  • Greg Kujawa Profile Picture
    565 on at
    And I did take a look into how Visual Studio is handling server certificates when debugging. It by default creates the server certificate when first launched. I can verify this, since Ctrl+Clicking on the request URL that my BC codeunit procedure is using launches a web browser. Where the response works fine, and there is no server certificate warnings when hitting the https endpoint on localhost.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,175

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,476 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,435 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans