web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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

(4) ShareShare
ReportReport
Posted on by 2
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,165 Super User 2026 Season 1 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
    2 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,165 Super User 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 509 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans