Search code examples
phpcurlodatamicrosoft-dynamicsmicrosoft-dynamics-nav

Simple HTTP request to Odata web service works fine on localhost, but fails on server


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?


Solution

  • I have detected the cause of the problem :

    • The Odata web service in Microsoft Dynamics NAV 2016 uses port 1103
    • Port 80, 443, 25 and 110 are the only ports open on the server from which I'm trying to call the service

    It is not an option for our Microsoft Dynamics provider to change the port they're using, nor an option for our web hosting provider to open this port for us.

    After a discussion with my boss, we've agreed to move our web hosting to another provider that gives us more flexibility and does not block port 1103.