0

i got this error System.Net.Http.HttpRequestException: ‘The SSL connection could not be established in C# when using this api https://api.codebazan.ir/arz/?type=arz but when i use this api https://corona.lmao.ninja/v3/covid-19/countries?sort=cases i dont get any error this is my code

 static async System.Threading.Tasks.Task Main(string[] args)
    {
        using (HttpClient client = new HttpClient())
        {
            string request = "https://api.codebazan.ir/arz/?type=arz";
            HttpResponseMessage apirequest = await client.GetAsync(request);

            string jsonResponse = await apirequest.Content.ReadAsStringAsync();

        }
    }

i use window 8.1 and visual studio 2019 any help will be highly appreciated

  • And does your PC trust Let's Encrypt certificates? – Charlieface Feb 09 '21 at 14:26
  • What version of Net are you using? Are you using Core? This gets complicated. What works most of the time is to add at beginning of the code : ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; – jdweng Feb 09 '21 at 14:49
  • I think first link is using TLS 1.2 and second link TLS 1.3. So use OR : ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 |SecurityProtocolType.Tls13; – jdweng Feb 09 '21 at 14:56
  • i dont know exactly dear @Charlieface how should i check it? – reza setareh Feb 09 '21 at 15:13
  • i checked different types of your code but none of them solved my problem dear @jdweng yes im using .net core anyway i will see this error – reza setareh Feb 09 '21 at 15:15
  • Which version of Core? There probably an issue with using TLS 1.3. Microsoft switched from doing TLS in Net to letting the operating System perform the TLS. So I can't tell if issue is with Net version or the Operating System. – jdweng Feb 09 '21 at 15:57
  • i use .net core3.1 @jdweng – reza setareh Feb 10 '21 at 07:06
  • Are you using a mobile application on Linux? See : https://stackoverflow.com/questions/57900809/does-net-core-3-support-tls-1-3 – jdweng Feb 10 '21 at 10:50
  • @jdweng no i dont use – reza setareh Feb 10 '21 at 15:28
  • I don't think Windows 8.1 supports the TLS version. VS is using a new version of Net which lets operating System perform TLS instead of inside Net. What may work is to use VS 2019 but target older version of Net where TLS is done in Net instead of using Operating System. – jdweng Feb 10 '21 at 16:08

0 Answers0