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.

5
  • 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? Commented Feb 25, 2020 at 12:33
  • 1
    Does this answer your question? The request was aborted: Could not create SSL/TLS secure channel Commented Feb 25, 2020 at 12:35
  • In fact, all browsers will ditch TLS 1.1 and lower in less than a month. Commented Feb 25, 2020 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 Commented Feb 25, 2020 at 12:39
  • But I am on Windows 10, VS 2019 and Targeting .NET 4.5 Commented Feb 25, 2020 at 14:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.