Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure函数上的HttpRequest不';无法使用https_C#_Azure_Https_Azure Functions_Httprequest - Fatal编程技术网

C# Azure函数上的HttpRequest不';无法使用https

C# Azure函数上的HttpRequest不';无法使用https,c#,azure,https,azure-functions,httprequest,C#,Azure,Https,Azure Functions,Httprequest,我创建了一个简单的Azure函数(Http触发器),我想通过C#代码调用它。 我知道为了调用它,我必须使用Azure门户中显示的函数URL执行http请求。但是,当到达GetAsync(…)方法时,我得到了一个HttpRequestException(发送请求时出错)。这是我的代码: public static void Main(string[] args) { AsyncMain(); Console.ReadKey(); } static async vo

我创建了一个简单的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函数讲TLS1.2,而您的项目可能以默认为TLS1.0的.NET 4.5或4.6为目标,所以握手失败


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

添加代码
ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12应用程序启动中。因为Azure函数讲TLS1.2,而您的项目可能以默认为TLS1.0的.NET 4.5或4.6为目标,所以握手失败


尝试显式配置安全协议-将此代码添加到应用程序启动中的某个位置:
ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12这似乎解决了问题。谢谢杜桑!没问题。由于某些原因,某些环境/网络需要此功能。。。在其他情况下,它只是开箱即用。原因是Azure函数讲TLS 1.2,而您的项目可能以默认为TLS 1.0的.NET 4.5或4.6为目标,因此握手失败。如果重新定位到4.6.2+或直接定位到.NET 5,则不需要额外的ServicePointManager configuration.BTW,在C#中,异步主要支持了4-5年的良好运行—尝试显式配置安全协议—将此代码添加到应用程序启动中的某个位置:
ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls12这似乎解决了问题。谢谢杜桑!没问题。由于某些原因,某些环境/网络需要此功能。。。在其他情况下,它只是开箱即用。原因是Azure函数讲TLS 1.2,而您的项目可能以默认为TLS 1.0的.NET 4.5或4.6为目标,因此握手失败。如果您将目标重新定为4.6.2+或直接定为.NET 5,您将不需要额外的ServicePointManager配置。顺便说一句,现在C#提供了异步主要支持,可以持续4-5年-