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...
Answered

httpclient always return false in sandbox container local

(0) ShareShare
ReportReport
Posted on by

Hi everyone, 

I'm completely new to Dynamics 365 and specifically to Business Central. I was trying to make an Http call in sandbox container local, but what I got is httpclient.get() returned false.

when i try to installed and published to the sandbox online, it works. I don't know why not working on sandbox container local, can somebody help me? 

here's my PowerShell script to create container

$accept_eula = $true

$containername = 'testing-bc2'
$navdockerimage = 'xxx.com/businesscentral/sandbox:XXXXX-au'
$appbacpacuri = ''
$tenantbacpacuri = ''
$additionalParameters = @()
if ($appbacpacuri -ne '' -and $tenantbacpacuri -ne '') {
    $additionalParameters = @("--env appbacpac=""$appbacpacuri""","--env tenantBacpac=""$tenantbacpacuri""")
}

$credential = get-credential -UserName $env:USERNAME -Message "Using Windows Authentication. Please enter your Windows credentials."
New-NavContainer -accept_eula:$accept_eula `
                 -memoryLimit 4G `
                 -containername $containername `
                 -auth NavUserPassword `
                 -Credential $credential `
                 -alwaysPull `
                 -doNotExportObjectsToText `
                 -usessl:$false `
                 -updateHosts `
                 -assignPremiumPlan `
                 -shortcuts Desktop `
                 -imageName $navdockerimage `
                 -additionalParameters $additionalParameters

Setup-NavContainerTestUsers -containerName $containername -password $credential.Password

here's my code

procedure FetchRandomUser()
    var
        Client: HttpClient;
        Response: HttpResponseMessage;
        Request: HttpRequestMessage;
        Header: HttpHeaders;
        Url: Text;
        ResponseText: Text;
        ResContent: HttpContent;
    begin
        Url := 'https://randomuser.me/api/';
    if Client.Get(Url, Response) then begin
            Message('SUCCESS');

            Response.Content.ReadAs(ResponseText);
            Message(ResponseText);
        end;
    if Response.HttpStatusCode() = 200 then begin

            ResContent := Response.Content();
            ResContent.ReadAs(ResponseText);
            Message(ResponseText);
    end;
        Message('httpstatusCode %1, reason%2', Response.HttpStatusCode, Response.ReasonPhrase);
    end;

I got HttpStatusCode 200 but its throw an error

pastedimage1597139820175v1.png

I have the same question (0)
  • Suggested answer
    Dan Kinsella Profile Picture
    468 on at

    Your code works fine for me on my local container.

    Perhaps it's a firewall issue?

    Have you tried accessing that URL from a web browser or Postman from the machine hosting your container?

  • Community Member Profile Picture
    on at

    its hosted on local, yes i have tried that from a web browser and Postman. can u share your PS script ? maybe i miss something

  • Suggested answer
    Dan Kinsella Profile Picture
    468 on at

    Sure, I used this:

    $artifactUrl = Get-BCArtifactUrl -type sandbox -country gb -select Latest

    $credential = New-Object pscredential 'admin', (ConvertTo-SecureString -String 'P@ssword1' -AsPlainText -Force)

    New-BcContainer `

       -accept_eula `

       -containerName test `

       -artifactUrl $artifactUrl `

       -Credential $credential `

       -auth UserPassword `

       -updateHosts `

       -enableTaskScheduler

    As you're getting your database from a bacpac, you might want to check that the http client hasn't been disabled (although you would have got a message pop up): www.kauffmann.nl/.../

  • Community Member Profile Picture
    on at

    httpclient for my extension is enabled broo, but still not working on my local container. is there any possibility because of the image I used? I'm using image from PS script generated from BC Cloud.

  • Verified answer
    Dan Kinsella Profile Picture
    468 on at

    Not sure why that would make a difference, but have you tried using my script? It will create a sandbox container on the latest release.

    Something else you might want to try is to see if you can download a web page, if you can't you've got a networking / firewall issue.

    Try these commands from PowerShell:

    PS C:\windows\system32> Enter-BCContainer test

    [TEST]: PS C:\Run> Invoke-WebRequest http://google.com -OutFile "C:\Run\test.html"

    [TEST]: PS C:\Run> Get-Content C:\run\test.html

  • Community Member Profile Picture
    on at

    wow you right, I can't access

    do you know how to fix this? 

    lol, i just need to add this in my PS Script: 

    -dns '8.8.8.8'

    Thanks.
  • cuge89 Profile Picture
    5 on at

    Hi guys, i'll ask here instead of starting a new thread because i'm facing a similar problem. 

    I did a test application sending a get request with ..  HttpClient.Get(...url... , Response), and was all working fine, i did the same on my customer's BC (onPrem, same version as test environment) but it doesnt work, same code, same Url. 
    I tried every possible solution i found on the forums/blogs, no way out. 

    Interesting facts:  
    - if i try to change Url with https://www.google.com it still wont work, but if i go with http instead of https, it does work. 
    - i tried to go with http also for the original url, but didnt work
    - if i try with the powershell command mentioned above "Invoke-WeRequest", it works with every url, either http or https. 

    so i'm really confused at this point, why shouldnt this work in my code aswell ? 

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 2,468

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans