2

I'm getting an exception while this code executes, the url i try to connect is an https (SSL)

Someone knows why I get this error? Cuz I can navigate that url in chrome normally

FYI: I'm debuging this locally...

HtmlDocument doc = new HtmlWeb().Load(url);

The SSL connection could not be established, see inner exception. Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine

dustinos3
  • 934
  • 3
  • 17
  • 27
Pablitros
  • 125
  • 1
  • 6
  • What version of .NET are using in the local code? – ADyson Nov 12 '19 at 18:24
  • Hi Pablitros, may I know if the answer I provided helps your problem ? If it works, could you please [mark](https://stackoverflow.com/help/someone-answers) my answer as "accepted" ? Thanks in advance~ – Hury Shen Nov 14 '19 at 01:33
  • It helped, the main thing that was happening is that azure by default enables ssl and that was the reason why I was getting that error – Pablitros Nov 20 '19 at 17:40

1 Answers1

0

"HtmlWeb" doesn't support load from "https", it just support "http". You can refer to these two links: link1 and link2.

If you want to load the document from https, you can use HttpWebRequest as a workaround. Here is a post for your reference.

The workaround(HttpWebRequest) above maybe just work in .net framework 4.6.1, so I post another workaround here. We can also use "HttpClient", please refer to the code below:

using System;
using System.Net.Http;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "https://google.com";

            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage response = client.GetAsync(url).Result)
                {
                    using (HttpContent content = response.Content)
                    {
                        string result = content.ReadAsStringAsync().Result;
                        Console.WriteLine(result);
                    }
                }
            }
        }
    }
}

Hope it would be helpful to your problem~

Hury Shen
  • 14,948
  • 1
  • 9
  • 18