0

`Error coming: The client and server cannot communicate because they do not possess a common algorithm.

enter image description here

enter image description here,,,, In Global.asax.cs I have added :

        `// using System.Net;
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;`

In Web.config: <system.web> <compilation debug="true" targetFramework="4.8" /> <httpRuntime targetFramework="4.8" />

and in controller calling api:

       `var request = WebRequest.Create("https://********receivesms_xml.html");

        request.Method = "POST";           

        byte[] byteArray = Encoding.UTF8.GetBytes(Content);
        request.ContentType = "text/html; charset=UTF-8";
        request.ContentLength = byteArray.Length;
        
        
        using (Stream dataStream = request.GetRequestStream())
        {
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
        }`

Error coming: The client and server cannot communicate because they do not possess a common algorithm.

Please advise. Thank YOu.

I have tried adding code before web request start to add tls13,

       ` // using System.Net;
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;`

and I have added In window registry, tls12

bhatti
  • 3
  • 3
  • The error message is a timeout message indicating the connection did not complete. The error can be caused by TLS failing or any other reason that the connection did not complete. Net cannot detect just the TLS failure because TLS is done by the OS before the request is sent. TLS requires a common Certificate to be loaded on both the client and server before the request is sent. The only real way of telling what caused the error is to use a sniffer like wireshark or fiddler. If TLS fails you will never see the HTTP request sent. If you do see the HTTP request than TLS passed. – jdweng May 13 '23 at 15:08
  • Did code ever work with TLS 1.2? The certificate has an encryption mode and some modes will only work with 1.2, others will work with only 1.3, and others will work with both 1.2 and 1.3. See Wiki : https://en.wikipedia.org/wiki/Transport_Layer_Security – jdweng May 13 '23 at 15:09
  • What OS exists on the computer that is running your application? – Tu deschizi eu inchid May 13 '23 at 16:39
  • The following may be of interest [Protocols in TLS/SSL (Schannel SSP)](https://learn.microsoft.com/en-us/windows/win32/secauthn/protocols-in-tls-ssl--schannel-ssp-#tls-protocol-version-support) and [Transport Layer Security (TLS) best practices with the .NET Framework](https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls) – Tu deschizi eu inchid May 13 '23 at 16:39
  • OS; Windows 10 Pro, Verson: 21H1, OS Build: 19043.1741, Experience: Windows Feature Experience Pack 120.2212.4180.0 – bhatti May 14 '23 at 08:09
  • @jdweng: Previous developer told me the api request was working with tls1.2, now upgraded on server to tls1.3, I am unable to call, however I called the api from postman, and it called successfully, – bhatti May 14 '23 at 08:11
  • @Tudeschizieuinchid: I have Windows 10, in window registry I have added enabled tls1.2, tls1.3, but still unable to call. – bhatti May 14 '23 at 08:15
  • 'The request was aborted: Could not create SSL/TLS secure channel.' now this error coming.......... – bhatti May 14 '23 at 08:19
  • Postman may be performing the connection using a built in OpenSSL library while your code is using the Windows OS and that would explain why one is working and one is not working. Postman is working we now know that the certificate is properly loaded. The OS is Win10 which indicates the OS should support the encryption mode. I would change code to use either 1.2 or 1.3 : SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13; I would also disable proxy instead of using default proxy : https://stackoverflow.com/questions/1155363/how-to-autodetect-use-ie-proxy-settings-in-net-httpwebrequest – jdweng May 14 '23 at 09:23
  • The issue may be the proxy can handle TLS 1.2 but not TLS 1.3. Postman may not be using the proxy. – jdweng May 14 '23 at 09:24
  • It's not clear how you _in window registry I have added enabled tls1.2, tls1.3_ The following should work to enable TLS 1.3 in Win 10: https://stackoverflow.com/a/70674920/10024425 (replace references to _TLS 1.2_ to _TLS 1.3_) – Tu deschizi eu inchid May 14 '23 at 14:14
  • The following may be of interest: [How to: Configure network tracing](https://learn.microsoft.com/en-us/dotnet/framework/network-programming/how-to-configure-network-tracing) – Tu deschizi eu inchid May 14 '23 at 14:19

0 Answers0