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 :
Microsoft Dynamics NAV (Archived)

Curl error: Failed to connect to {IP} port {PORT}: Connection timed out - MS Dynamics NAV 2016 - PHP

(0) ShareShare
ReportReport
Posted on by

Hello,

I have an integration on my website with Microsoft Dynamics NAV (2016) to Create, Read, Update, Delete data. Website is based on Wordpress therefore I am using PHP to send the requests but having some troubles to even read the data. Here is one of my code examples (as I tried many):

<?php
$soapUrl = "http://{IP}:{PORT}/TEST/WS/{CompanyName}/Page/PolicyList";
$xml_post_string = '<Envelope xmlns="schemas.xmlsoap.org/.../envelope">
    <Body>
        <Read xmlns="urn:microsoft-dynamics-schemas/page/policylist">
            <Policy_No>P0000</Policy_No>
        </Read>
    </Body>
</Envelope>';

$action = "urn:microsoft-dynamics-schemas/page/policylist:Read";
$ipAddress = "{SERVER IP}";
$headers = array(
    'Method: POST',
    'Accept: text/xml',
    'Host: {IP}:{PORT}',
    'Connection: Keep-Alive',
    'Cache-Control: private',
    'Pragma: no-cache',
    'User-Agent: PHP-SOAP-CURL',
    'Content-Type: text/xml; charset=utf-8',
    'SOAPAction: urn:microsoft-dynamics-schemas/page/policylist:Read',
    'Content-length: '.strlen($xml_post_string),
);

$url = $soapUrl;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "{username}:{password}");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_INTERFACE, $ipAddress);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);

if(curl_exec($ch) === false) {
    echo 'Curl error: ' . curl_error($ch);
} else {
    echo 'Operation completed!';
}
curl_close($ch);
?>

I always get "Curl error: Failed to connect to {IP} port {PORT}: Connection timed out" error.

I could load services only via Chrome extension called "Wizdler". I can send and receive back the data very easily. But can't reach that via PHP.

Does anyone know what I am doing wrong pls? Appreciate your help.

Thanks

*This post is locked for comments

I have the same question (0)
  • Poorva Virtuos Profile Picture
    5 on at

    Hi,

    Were you able to solve this issue?

    I am facing the same, would be glad if you could share the fix.

    Regards

  • Suggested answer
    Alexander Ermakov Profile Picture
    28,096 on at

    There have been few discussion threads before, might be helpful:

    community.dynamics.com/.../api-integration-using-php

    freddysblog.com/.../

    freddysblog.com/.../

    and custom 3rd party solutions, e.g. www.cdata.com/.../dynamicsnav-connect-php.rst

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 > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans