我在执行此代码时遇到异常,我尝试连接的 url 是 https (SSL)
有人知道我为什么会收到这个错误吗?因为我可以在 chrome 中正常浏览该 url
仅供引用:我正在本地调试...
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
最佳答案
“HtmlWeb”不支持从“https”加载,只支持“http”。可以引用这两个链接:link1和 link2 .
如果你想从https加载文档,你可以使用HttpWebRequest作为解决方法。这是一个 post供大家引用。
上面的解决方法 (HttpWebRequest) 可能只适用于 .net Framework 4.6.1,所以我在这里发布了另一个解决方法。我们也可以使用“HttpClient”,请引用下面的代码:
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);
}
}
}
}
}
}
希望对你的问题有所帮助~
关于c# - Azure 函数无法建立 SSL 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58823893/