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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Could not establish trust relationship for the SSL/TLS secure channel

(3) ShareShare
ReportReport
Posted on by
Hi everyone,
I am trying to call an external web API in d365fo x++ but I am getting an error when I pass the server url and header parameters. The error message is /The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel./ I am wondering if anyone has encountered this error before and knows how to fix it.
Here is my code for calling the external API:
 
 
       System.Net.HttpWebRequest request;
        System.IO.Stream stream;
        System.Exception sysEx;
        System.Net.ServicePointManager::SecurityProtocol=System.Net.SecurityProtocolType::Tls12;
   
        request = System.Net.WebRequest::Create(/url/) as System.Net.HttpWebRequest;
        request.Method = 'POST';
        request.ContentType = 'application/json';
        // Set the request headers
        System.Net.WebHeaderCollection headerCollection = request.Headers;
        headerCollection.Set('Authorization', 'Bearer XXXXXXXXXXXXX');
        var utf8 = System.Text.Encoding::get_UTF8();
  
        // Set the request body
        var byteArrayPayload = utf8.GetBytes(/string value/);
     
     
        try
        {
            // send out the payload
            using (System.IO.Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArrayPayload, 0, byteArrayPayload.Length);
            }
            using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
            {
           
                stream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(stream);
                str responseBody = reader.ReadToEnd();
            }
        }
        catch (sysEx)
        {
            throw;
        }
 
I have the same question (0)
  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi User,

    Did you try to call this URL from postman and it worked?

    To double check if it's an issue from the code or not, then please try to call a public API url in your x++ code
    Choose one of the public APIs here and let us know (https://documenter.getpostman.com/view/8854915/Szf7znEe)

    Thanks,
    Layan Jweihan
  • Community member Profile Picture
    on at
     
    I have tried the API using Postman and it works fine. I have also tested it in a C# console application and it works as expected. However, when I use the API in X++, I get this error. Do you have any idea what could be causing this problem? Thank you for your help.
  • Suggested answer
    Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Hi User,

    Did you try to call the public api i gave you in the previous reply using x++? if it works, then the issue is not from your code and might be related to firewall or security. However, if it doesn't work as well, then there might be sth with the code. so please confirm
     
    Thanks,
    Layan Jweihan

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans