gpt4 book ai didi

.net - 无法从 Azure 连接到 Nexmo API

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:16 27 4
gpt4 key购买 nike

我的应用程序托管在云上(microsoft azure),我正在尝试使用 https://api.nexmo.com/ni/basic/json?api_key=xxx&api_secret=xxxxxx&number= 验证手机号码,一切正常,然后突然我现在不再能够通过 azure 连接到 api,尽管我可以在本地连接到 api,但我收到此错误现有连接被远程主机强制关闭。我尝试将 TLS 更新到 V1.2,但我不断收到相同的错误。

这是我的代码:

string nexmoRes = Utilities.ReadGetHtmlPage("https://api.nexmo.com/ni/basic/json?api_key=xxxx&api_secret=xxx&number=" + InternationalMSISDN, "");

public static string ReadGetHtmlPage(string url, string str)
{
try
{
try
{
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
Utilities.writeLogs(System.Reflection.MethodInfo.GetCurrentMethod(), "url " + url);
objRequest.Method = "GET";
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
StreamReader sr;
sr = new StreamReader(objResponse.GetResponseStream());
return sr.ReadToEnd();
}
catch (Exception ex)
{
Utilities.WriteToText(ex);
return "";
}
}
catch (Exception ex)
{
Utilities.WriteToText(ex);
return "";
}
}

最佳答案

在应用服务上尝试过,对我来说效果很好,请确保您的目标是 .NET 4.7 in your web.config或在 ServicePointManager 中明确选择 TLS 1.2,因为您的 Remote 仅支持 TLS 1.2 —

$ curl -i --tlsv1.0 "https://api.nexmo.com/ni/basic/json"
curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed


$ curl -i --tlsv1.1 "https://api.nexmo.com/ni/basic/json"
curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed


$ curl -i --tlsv1.2 "https://api.nexmo.com/ni/basic/json"
HTTP/1.1 200 OK
Server: nginx
...
{
"status": 4,
"status_message": "Invalid credentials"
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
...

如果您选择此路线,请注意 ServicePointManager.SecurityProtocol 的范围是您的整个应用程序域。

以 .NET 4.7 为目标,而不是修改 ServicePointManager 将把你带到这里,一个更好的地方 -

TLS version matrix

带有 Windows 工作线程的应用服务在 Windows Server 2016 上运行 -

App Service OS

关于.net - 无法从 Azure 连接到 Nexmo API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51980331/

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