Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

"The request was aborted: Could not create SSL/TLS secure channel." On API Call

(0) ShareShare
ReportReport
Posted on by 40

Hi,

I am facing an error "The request was aborted: Could not create SSL/TLS secure channel." on calling an API to send data to a 3rd party application.
I found similar queries on community but those fixes doesn't worked for me.

The version of TLS is 1.2 on my local hosted VM. (Note: it doesn't work on UAT and Production as well).

please help me out with this one.

Thanks

Here is code that I am using:

		try
        {
            httpHeader = new System.Net.WebHeaderCollection();
            new InteropPermission(InteropKind::ClrInterop).assert();
            

            clrObj = System.Net.WebRequest::Create("URL");
            request = clrObj;

            // adding headers

            byteStr = System.Convert::ToBase64String(System.Text.Encoding::Default.GetBytes(user   ":"   pass));

            httpHeader.Add("Accept-Version", "V2");
            httpHeader.Add("Clearance-Status", "1");
            httpHeader.Add("Accept-Language", "en");
            httpHeader.Add("Authorization", 'Basic '   byteStr);

            

            request.set_Headers(httpHeader);

            request.Method = "POST";
            request.ContentType = "application/json";

            requestStream = request.GetRequestStream();
            streamWriter = new System.IO.StreamWriter(request.GetRequestStream());

            streamWriter.Write(jsonBody); // writing JSON
            

            response = request.GetResponse();

            streamWriter.Flush();
            streamWriter.Close();
            System.IO.StreamReader streamRead = new System.IO.StreamReader(response.GetResponseStream());

            Map responseMap = RetailCommonWebAPI::getMapFromJsonString(streamRead.ReadToEnd());

            MapEnumerator mapenum = responseMap.getEnumerator();
            /* Some code to validate the result */
        }
        catch
        {
            //exception
            ex = CLRInterop::getLastException().GetBaseException();
            error(ex.get_Message());
        }

  • Suggested answer
    Shahzaib Ahmed Profile Picture
    Shahzaib Ahmed 40 on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    We talked to Microsoft support it comes out to be the ciphers that were not configured on D365 FnO VMs.

    Configuring those resolved the issue.

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    Verify that the system trusts the issuer of the certificate.

    I would also review registry settings (Transport Layer Security (TLS) best practices with the .NET Framework > Configuring security via the Windows Registry), remove SecurityProtocol assignment and try if it makes a difference.

    You can also look at previous discussions (such as this or this). There are a few more ideas about possible reasons and ways of debugging. And ask in an appropriate forum if nothing helps.

  • Shahzaib Ahmed Profile Picture
    Shahzaib Ahmed 40 on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    try
    {
        string serviceOperationPath = "URL";
        ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
    
        //Serialize the object into stream before sending it to the remote server
        string json = JsonConvert.SerializeObject(apiRequest);
        byte[] data = Encoding.UTF8.GetBytes(json);
    
        HttpClient httpClient = new HttpClient();
        httpClient.BaseAddress = new Uri("BASEURI");
        httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.Default.GetBytes(complianceCSID   ":"   complianceSecret)));
        httpClient.DefaultRequestHeaders.Add("Accept-Version", "V2");
        httpClient.DefaultRequestHeaders.Add("Accept-Language", "en");
        httpClient.DefaultRequestHeaders.Add("Clearance-Status", "1");
    
        HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, "URLPOSTFIX");
        var content = new StringContent(json, Encoding.UTF8, "application/json");
        httpRequest.Content = content;
    
        var res = httpClient.SendAsync(httpRequest).Result;
    
    }
    catch (Exception ex)
    {
    }

    Here is the part of code that calls the API in C# Application

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    No, your initial code doesn't contain the fix that I suggested in my second reply.

    Also, it's not the C# code we're discussed in last replies. I understand that you want to use X++ code, but now we're talking about your test app written in C#.

  • Shahzaib Ahmed Profile Picture
    Shahzaib Ahmed 40 on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    The code is present in my initial question.

    I created C# just to check if that work in C# or not but it didn't worked in VM but it worked in my laptop with windows 10 (22H2 Build 19045.2965).

    My initial code is in F&O that I want to use.

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    I believe TLS 1.2. is enabled in Windows Server 2019 by default.

    Can you show us your current code (with Tls12 enabled), so we can review that it was done correctly?

    Since you have a problem with a pure C# application and it's not about F&O, consider asking in a .NET forum instead.

  • Shahzaib Ahmed Profile Picture
    Shahzaib Ahmed 40 on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    pastedimage1684307800895v1.png

    s the version of OS

    [quote]

    Version of the operating system where you're executing your code and getting the error. I'm assuming it's Windows Server.

    [/quote]
  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    Version of the operating system where you're executing your code and getting the error. I'm assuming it's Windows Server.

  • Shahzaib Ahmed Profile Picture
    Shahzaib Ahmed 40 on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    HTTP Client also gave same error.

  • Shahzaib Ahmed Profile Picture
    Shahzaib Ahmed 40 on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    My windows 10 version or windows server version?

    .NET framework version is 4.8

    I only tried it with WebRequest only.

    I'll try it again with httpClient and will update you shortly.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans