gpt4 book ai didi

c# - 仅在 azure 上 : Could not create SSL/TLS secure channel

转载 作者:太空狗 更新时间:2023-10-29 17:51:40 25 4
gpt4 key购买 nike

我在 Azure 应用程序标准:1 小型计划上运行应用程序。框架是4.6.1

此应用程序正在调用 SSL 安全 API。 SSL 由 StartCom Class 1 DV Server CA 发布,我的本地浏览器告诉我该证书有效。

如果我在本地计算机上运行该应用程序,一切正常。但是,当部署到 azure 时,它​​会失败并出现以下错误:

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)

--- End of inner exception stack trace ---

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

代码:

public async Task<List<QutationOverview>> GetAll(string url, DateTime lastActionDate)
{
var result = string.Empty;

try
{


var userName = await _settingManager.GetSettingValueAsync("API.UserName");
var password = await _settingManager.GetSettingValueAsync("API.Password");


ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;


ServicePointManager
.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;


//Add date filter
//Always request qutations where the last action took place >= Yesterday
var requestUrl =
$"GetALL/?last_action_date={lastActionDate.AddDays(-1).ToString("yyyy-MM-dd")}&format=json";


var baseAddress = new Uri(url);
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{userName}:{password}"));

Logger.InfoFormat("GetAllQuotationsAsync for url {0}{1}", url, requestUrl);

using (var httpClient = new HttpClient {BaseAddress = baseAddress})
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
using (var response = await httpClient.GetAsync(requestUrl))
{
result = await response.Content.ReadAsStringAsync();
Logger.Info(result);
}
}
}

catch (Exception ex)
{
Logger.ErrorFormat("GetAllQuotationsAsync {0}: {1}", url, ex);
}
var data = JsonConvert.DeserializeObject<List<QutationOverview>>(result);

return data;
}

如您所见,我跳过了证书验证并添加了安全协议(protocol)。

但是,请求仍然失败。

<小时/>

这是捕获的响应 http://textuploader.com/5ers0

<小时/>

您知道如何让这个在 Azure 上运行吗?

最佳答案

我在 Azure 的应用服务上托管客户端证书时遇到了此错误。修复方法是在应用程序设置中设置 WEBSITE_LOAD_CERTIFICATES。

您可以将其设置为“* ”以允许所有证书,也可以定义要允许的特定证书指纹。 See more info here.

关于c# - 仅在 azure 上 : Could not create SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38392925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com