samedi 27 avril 2019

C# Web exception unexpected EOF

I am attempting to download a json web page from imdb to find an actor.

        try
        {
            using (WebClient wc = new WebClient())
            {
                string content = wc.DownloadString("https://v2.sg.media-imdb.com/suggests/names/b/brad.json");
            }
        }
        catch (WebException x)
        {
            x.ToString();
        }

Whenever I attempt to make the download.

The exception given is:

The underlying connection was closed: An unexpected error occurred on a send.

And the inner web exception is:

Received an unexpected EOF or 0 bytes from the transport stream.

From what I've read. This happens because one of imdb's servers is misconfigured.

To try and solve this, I used

System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)(3072);

To set the security protocol to Tls12 which does solve the issue on my PC.

However, when I try to use it on my second PC. That line throws the exception:

System.NotSupported: The requested security protocol is not supported

Which I assume means that it doesn't have tls12 support on that PC.

I have the .NET Framework 4.5.1 installed on that PC and I cannot install .NET Framework 4.7 because it fails in the installation.

I assume the security protocol comes with 4.7, but I don't see that confirmed on MSDN.

How can I get the web page to download on this second PC?

Is there a way for me to manually install the Tls12 protocol?

Is there an alternative using HttpWebRequest or some standalone executable instead?




Aucun commentaire:

Enregistrer un commentaire