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

Community site session details

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

Business Central intermittent HttpRequest error with 3rd party web call

(0) ShareShare
ReportReport
Posted on by 49
I have a codeunit method that is called on a trigger OnOpenPage() for the Purchase Order screen. It is a POST http request for a 3rd party web service and it works most of the time, but from time to time I get the error below. I have looked at tryfunction, but with that I cannot return a user defined value. I have tried other ways to use a global to get my return value but it doesn't seem to work exactly the way I need with tryfunction. If I didn't need to return a value this would work for me. What I'm trying to do is suppress the error or catch it so it won't throw an error on the open page. (In the old days like an On error resume next would work here for me.) I can't seem to find why or how to go about this. I've looked at retry logic to retry the http request on fail, but that doesn't seem to work as well. I still get the error. The error below, second error is when I put additional error handing to try to get more details. I know it isn't the url or any other issues with the request itself because as I said it works 95% of the time, and when it does throw the error, after exiting the screen and going back the same request works without error.
 
Error message: 
There was an error while executing the HTTP request, error request: ConnectionError. Make sure you are connecting to a valid endpoint.
 
Error message after additional error handling: 
HTTP request failed with status code 0: NavHttpClient Request Failed
 
Code for request:
    procedure getApplicationOn() enabled: Boolean
    var
        request: HttpRequestMessage;
        response: HttpResponseMessage;
        contentHeaders: HttpHeaders;
        content: HttpContent;
        jObj: JsonObject;
        jtext: Text;
        IsSuccessful: Boolean;
        responseText: Text;
    begin
        if (getExternAppName() = '') then begin
            error('App Name is empty.');
        end;
        if (getScreenTitle() = '') then begin
            error('Screen Title is empty.');
        end;
 
        globalJsonObj.WriteTo(jtext);
        // Add the payload to the content
        content.WriteFrom(jtext);

        // Retrieve the contentHeaders associated with the content
        content.GetHeaders(contentHeaders);
        contentHeaders.Clear();
        contentHeaders.Remove('Content-Type');
        contentHeaders.Add('Content-Type', 'application/json');
        request.Content := content;
        request.SetRequestUri(getApplicationURL() + '/api/Integration/GetEnabled');
        request.Method := 'POST';
        globalHttpClient.Send(request, response);
 
        if not response.IsSuccessStatusCode then begin
            enabled := false;
            exit;
        end;
 
        // pass true, no error so application active and ready
        enabled := true;

    end;
 

 
I have the same question (0)
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,610 Super User 2025 Season 2 on at
    Business Central intermittent HttpRequest error with 3rd party web call
    globalHttpClient.Send(...) returns a Boolean — check it; status code 0 often shows up as a low-level connection issue.
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,610 Super User 2025 Season 2 on at

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,056

#2
YUN ZHU Profile Picture

YUN ZHU 1,680 Super User 2025 Season 2

#3
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 1,679

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans