0

I'm sorry for reposting this question. Just couldn't find an answer that was working for me.

Problem

This error occurs with Louis Vuitton's website but not with for example a specific ebay listing... "The underlying connection was closed: An unexpected error occurred on a receive. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm " This is the console's output after running the following code and I can't figure out why:

public static string checkThisProduct = "https://en.louisvuitton.com/eng-nl/products/time-out-trainers-nvprod2750020v";
        static void Main(string[] args)
        {
            GetInfoFromWeb(checkThisProduct);
        }
        public static void GetInfoFromWeb(string url)
        {
            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
                using (WebClient wb = new WebClient())
                {
                    string info = wb.DownloadString(url);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

Already Tried

Tried running this with no luck:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12;

Can this community help me out?

liudger
  • 31
  • 7
  • Webclient is a bit old. Now we use httpclient. Anyhow, is there an inner exception? – JHBonarius Mar 31 '21 at 20:30
  • when removing that try catch statement, the console gives: gives a long message: Unhandled Exception: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm – liudger Mar 31 '21 at 20:33
  • Hint is in the last sentence of the error. – Optional Option Mar 31 '21 at 20:55
  • Does this answer your question? [..The underlying connection was closed: An unexpected error occurred on a receive](https://stackoverflow.com/questions/21728773/the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-receiv) – Ken White Mar 31 '21 at 20:58
  • Stepping back a bit... what do you intend to do with the downloaded string? That site has lots of javascript and your downloaded string will not have the same content as what you see in the browser. – Crowcoder Mar 31 '21 at 21:00
  • @KenWhite read that post before posting this one, didn't help. – liudger Mar 31 '21 at 21:08
  • @OptionalOption does that simply mean I will be unable to achieve this? Or should I learn about something specific? – liudger Mar 31 '21 at 21:08
  • @Crowcoder trying to grab price data from websites. that's all. Don't really need Louis Vuitton but it caught my attention because I'm interested in why it won't let me grab the data! – liudger Mar 31 '21 at 21:11
  • And how about the dozens of other posts tagged C# and Webclient and that error message? – Ken White Mar 31 '21 at 21:12
  • @KenWhite well didn't read them all, but after looking through multiple pages of other posts tagged with c# and webclient, i decided to add mine to the list. I am really curious about why an ebay listing is ok and a louis vuitton product listing is a no go... they both seem to use the same TLS protocol etc. – liudger Mar 31 '21 at 21:20
  • Remove `SecurityProtocolType.Tls13`: you cannot use this protocol. You also need to specify in what System this code is run. What is the value of `SecurityProtocolType.SystemDefault` when inspected at run-time? The System version is more important, though. – Jimi Mar 31 '21 at 21:26
  • Checking the handshake, the server expects the Accept header to be set: add `wb.Headers.Add(HttpRequestHeader.Accept, "ext/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8");`. The `User-Agent` header is not required. If you're on Windows 7 or e.g., Windows Server 2008R2, add `ServicePointManager.ServerCertificateValidationCallback += (s, cert, ch, sec) => { return true; };` in case it doesn't work anyway. The Protocol is of course `TLS12` (if you have a Windows client). -- As already mentioned, the page is heavily scripted, you may need a head-less WebBrowser or HtmlAgilityPack. – Jimi Mar 31 '21 at 21:54
  • I also found that that site is heavily scripted and protected. Requests with no "Host" header return an "400 bad request - Invalid URL". Requests with /only/ a Host header are blocked. Etc, etc. You need *both* "Host" and "Accept=*/*", at least in PostMan. I also found the _abck cookie, which belongs to the Akamai Bot Manager... So the site is just heavily protected against non-browser downloads. – JHBonarius Apr 01 '21 at 07:15
  • @Jimi what do you mean I can't use `SecurityProtocolType.Tls13`. I'm running win 10 version 2004. How is the system version important? I'm having many questions as you can see, are there some articles you could recommend me to read before I continue this? – liudger Apr 02 '21 at 19:28
  • TLS13 is only partially implemented and it requires full System support, which is provided only in the newest version of the Sever edition, Windows Server 2022. You cannot use this protocol as it is right now. You'll have to implement it yourself (handling handshake, transaction, authentication, certificates exchange using dedicated Cipher Suites etc.). Previous versions of Windows Client have other limitations. Windows 7, for example, can handle TLS12, but it doesn't have all the Cipher suites available, so a TLS12 handshake may fail anyway. That's why the System version is important. – Jimi Apr 02 '21 at 19:37
  • Still using Windows 7 as example: if you don't use .Net Framework 4.8, you may find out that `SecurityProtocolType.SystemdDefault` actually defaults to SSL3/TLS1.0. But it may not default to TLS12 anyway, if that machine has not performed all the security updates available. So you cannot count on `SystemDefault`, you have to check what `SystemDefault` actually is and set `ServicePointManager.SecurityProtocol` to one or more versions that you want to support. (probably just TLS12, or ask the users if they want to allow a less secure protocol, in case the transaction requires it). – Jimi Apr 02 '21 at 20:12
  • See [Which TLS version was negotiated?](https://stackoverflow.com/a/48675492/7444103). – Jimi Apr 02 '21 at 20:13

0 Answers0