0

This below is all my code which is a copy paste from Web API book I am reading.

public class PageSizeController : ApiController
{
    private static string TargetUrl = "http://apress.com";

    public long GetPageSize()
    {
        WebClient wc = new WebClient();
        Stopwatch sw = Stopwatch.StartNew();
        byte[] apressData = wc.DownloadData(TargetUrl);
        Debug.WriteLine("Elapsed Time: ", sw.ElapsedMilliseconds);
        return apressData.LongLength;
        }
    }
}

When I make the API call : http://localhost:38000/api/pagesize

It throw this exception on DownloadData method:

System.Net.WebException: 'The request was aborted: Could not create SSL/TLS secure channel.'

This is not very welcoming when you open a book to follow the examples and it just doesn't work for their HelloWorld application.

Johnathan Barclay
  • 18,599
  • 1
  • 22
  • 35
Bohn
  • 26,091
  • 61
  • 167
  • 254
  • 1
    If you google for this message you'll find that this is caused by the lack of support for TLS1.2 on the OS/runtime you use. There are a *lot* of duplicate SO questions about this. By now, almost all major services have stopped supporting anything less than TLS1.2 . What .NET Runtime and OS are you targeting? – Panagiotis Kanavos Feb 25 '20 at 12:33
  • 1
    Does this answer your question? [The request was aborted: Could not create SSL/TLS secure channel](https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel) – Luthfi Feb 25 '20 at 12:35
  • In fact, all browsers will ditch TLS 1.1 and lower in less than a month. – Panagiotis Kanavos Feb 25 '20 at 12:37
  • You're probably using an unsupported and upatched OS or an unsupported .NET runtime. *Supported* Windows OS versions work with TLS 1.2 already, and .NET 4.6+ will use the OS's highest supported TLS version. The earliest supported .NET version is .NET 4.5.2 – Panagiotis Kanavos Feb 25 '20 at 12:39
  • But I am on Windows 10, VS 2019 and Targeting .NET 4.5 – Bohn Feb 25 '20 at 14:35

0 Answers0