Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

HTTP requests to Microsoft Dynamics NAV Odata web services work fine on localhost, but fail on server

Posted on by 45

I'm trying to send a basic HTTP request to an Odata web service in Microsoft Dynamics NAV 2016, using the following PHP code :

$url = 'https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer(\'1\')';
$credentials = 'user:password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json',
    'Content-Type: application/json'
]);
$output = curl_exec($ch);
curl_close($ch);

echo $output;

This code returns the expected result when I execute it on localhost.

However, when I execute this same code on my server, the browser keeps waiting for a response until a timeout.

I also tried using the HTTPful library :

$url = 'https://<Server>:<WebServicePort>/<ServerInstance>/OData/Company(\'<CompanyName>\')/customer(\'1\')';

$response = \Httpful\Request::get($url)
    ->sendsJson()
    ->authenticateWith('user', 'password')
    ->addHeaders([
        'Accept' => 'application/json',
        'Content-Type' => 'application/json'
    ])->send();

echo json_encode($response->body, JSON_PRETTY_PRINT);

Results were the same.

Both localhost and server use PHP5.5 and have cURL enabled, and sending a GET request to eg. http://en.gravatar.com/johnslegers.json works just fine on the server.

Any idea what might cause this and/or how to fix it?

*This post is locked for comments

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans