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

Community site session details

Session Id :
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());
        }

I have the same question (0)
  • Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    RE: "The request was aborted: Could not create SSL/TLS secure channel." On API Call

    You mentioned you have this code in production, therefore I assume it used to work before. Is it the case? When did it stopped working? At the same time in all environments? Or after installation of an update?

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

    I created this code on 25th January, 2023. and tested it then it worked and now on last Thursday I tested it before delivery it didn't worked. Then I deployed it on UAT tested it there it didn't worked and on live also. before this Thursday it was not not deployed on UAT and Live. Version of my Dynamics is Same as January 25th.

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

    All right, I didn't expect that you deploy code to production even if you know that it doesn't work.

    If I simplify your code a bit (and fixed a few things), I think the relevant part may look like this:

    void method1()
    {
    	System.Exception ex;
    
    	try
    	{
    		request = System.Net.WebRequest::Create("URL");
    		request.Headers = this.createHeaders();
    		request.Method = "POST";
    		request.ContentType = "application/json";
    
    		using (Stream requestStream = request.GetRequestStream())
    		{
    			using (StreamWriter streamWriter = new System.IO.StreamWriter(request.GetRequestStream())
    			{
    				streamWriter.Write(jsonBody); // writing JSON
    				
    				using (System.IO.StreamReader streamRead = new System.IO.StreamReader(response.GetResponseStream()))
    				{
    					response = request.GetResponse();
    				}
    			}
    		}
    	}
    	catch (ex)
    	{
    		throw error(ex.Message);
    	}
    }
    
    private WebHeaderCollection createHeaders()
    {
    	str byteStr = System.Convert::ToBase64String(System.Text.Encoding::Default.GetBytes(user   ":"   pass));
    
    	var headers = new System.Net.WebHeaderCollection();
    	headers.Add("Accept-Version", "V2");
    	headers.Add("Clearance-Status", "1");
    	headers.Add("Accept-Language", "en");
    	headers.Add("Authorization", 'Basic '   byteStr);
    	
    	return headers;
    } 

    Regarding the fix, try calling the following (before making the request):

    System.Net.ServicePointManager::SecurityProtocol = System.Net.SecurityProtocolType::Tls12;

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

    It gave same error.

    1 thing to note I created an C# app to call same API it works when I run it from my laptop. and when I move VS project to VM it gives me same error.

    Is there anything wrong with configuration or something like that?

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

    What is your OS version? Which version of .NET Framework is your C# app targeting?

    WebRequest class is obsolete. Will you have the same problem if you use HttpClient instead?

  • Shahzaib Ahmed Profile Picture
    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.

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

    HTTP Client also gave same error.

  • Martin Dráb Profile Picture
    237,679 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
    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
    237,679 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.

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 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans