c# - Azure 函数无法建立 SSL 连接

标签 c# ssl azure-functions

我在执行此代码时遇到异常,我尝试连接的 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”。可以引用这两个链接:link1link2 .

如果你想从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/

相关文章:

c# - 将对象序列化为最小的 UTF8 兼容大小

c# - 从代理服务器后面添加 Web 服务引用

java - 由于 SSLException 无法连接到 SQLServer

ssl - socat - 如何监听非 ssl TCP 并转发到 ssl TCP 端点?

macos - 如何在 Mac OS X 上启用 curl SSL?

azure - 使用 Azure Functions 启用 CORS 通配符子域

Azure Function App VNet 集成自定义 DNS

c# - asp.net mvc + knockout : Showing validation result from server side logic

c# - 取消长时间运行的 Dapper 查询

azure - 启用应用程序洞察会中断我的 Azure 功能吗?