1

I'm creating a application that will search for lyrics based on what you are listening on Spotify. For that I need to fetch the html from sites that provide lyrics (yeah, I know, not really compliant to their EULA, but it's for school/private use). The original function (see below) broke, so I decided to do some research on other ways, as it appeared to me to be the function not being able to use https. So after a 'quick' Google session I've found another function, but it still gives the same error when I try to access https://www.musixmatch.com (or another url on that domain): System.Net.WebException occurred The request was aborted: Could not create SSL/TLS secure channel.

But; when I use https://www.google.com or https://stackoverflow.com both functions work just fine. What is different to those sites in comparison to Musixmatch? Am I missing what the SSL/TLS secure channel exactly is? The things I find on Google tell me that it has to do with the SSL (how I found the new function), but given that it functions correctly with other SSL pages, I guess that there has to be something else. I am using HTMLAgilityPack, not sure if that makes a difference.


Original function

As the source variable one can for example use https://www.musixmatch.com/lyrics/Hundredth/Restless

public string retrieveLyrics()
{
    retrieveSource(true);
    var htmlWeb = new HtmlWeb();
    var documentNode = htmlWeb.Load(source).DocumentNode;

    var findclasses = documentNode
        .Descendants("p")
        .Where(d => d.Attributes["class"]?.Value.Contains("mxm-lyrics__content") == true);

    var text = string.Join(Environment.NewLine, findclasses.Select(x => x.InnerText));
    return text;
}

To repeat the question: Why does the function work when using a site like https://www.google.com, but not on https://www.musixmatch.com?

Community
  • 1
  • 1
MagicLegend
  • 328
  • 1
  • 5
  • 22
  • it depends on how the certs are setup. – Daniel A. White Mar 17 '17 at 18:43
  • This is normally due to a TLS protocol mismatch between client and server. Which version of .net and OS are you using? You can try this post to work around and test if it's their certificate issue http://stackoverflow.com/a/2675183/797375 – Imran Saeed Mar 17 '17 at 18:43
  • @i.net I'm using .NET 4.5.2 on Win10 – MagicLegend Mar 17 '17 at 19:01
  • @Alexei Levenkov (who marked it as a duplicate): Please note that the accepted answer there wasn't (directly) the answer to my question. – MagicLegend Mar 17 '17 at 19:07
  • @MagicLegend acceptance means almost nothing about the answer - it only mean OP liked it for whatever reason (including accepting completely wrong answers sometimes). If you feel that duplicate does not answer your question - make sure to [edit] the post to clarify how it did not solve your problem (and possibly unaccept answer here as presumably it is not what you were looking for). – Alexei Levenkov Mar 17 '17 at 21:14

1 Answers1

2

The most probable reason is that these websites use different TLS versions. Check out this answer.

Try doing this before your code to enable all possible versions:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
        | SecurityProtocolType.Tls11
        | SecurityProtocolType.Tls12
        | SecurityProtocolType.Ssl3;
Community
  • 1
  • 1
Andre Pena
  • 56,650
  • 48
  • 196
  • 243