繁体   English   中英

Azure 函数上的 HttpRequest 不适用于 https

[英]HttpRequest on Azure Function doesn't work with https

我创建了一个简单的 Azure 函数(Http 触发器),我想通过 C# 代码调用它。 我知道为了调用它,我必须使用 Azure 门户中显示的函数 URL 执行 http 请求。
但是,当达到 GetAsync(...) 方法时,我收到了 HttpRequestException(发送请求时发生错误)。 这是我的代码:

public static void Main(string[] args)
{
        AsyncMain();
        Console.ReadKey();
}

static async void AsyncMain()
{
        HttpResponseMessage response = await client.GetAsync("https://someapp.azurewebsites.net/api/somefunction?name=somevalue");
        response.EnsureSuccessStatusCode();
        string responseString = await response.Content.ReadAsStringAsync();
        Console.WriteLine(responseString);
}

当我将代码中的 URL 字符串从 https 更改为 http (http://someapp.azurewebsites[...]) 时,它工作正常。 直接从浏览器窗口运行该函数时也没有任何错误。 所以我怀疑我的请求有问题。

有人可以告诉我如何使用从 Azure 门户获得的正确链接对我的函数执行 HTTPS 请求吗?
提前致谢!

将评论总结为其他社区参考的答案:

添加代码ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 在应用程序启动中。 由于 Azure Functions 使用 TLS 1.2,并且您的项目可能针对 .NET 4.5 或 4.6(默认为 TLS 1.0),因此握手失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM