当我在 localhost 中运行我的应用程序时,它工作正常,但是当我将它发布到 Azure 时,我的请求停止工作。收到错误消息:“请求已中止:无法创建 SSL/TLS 安全通道。”
我有一个调用外部商业 Soap-API 的应用程序。外部 API 需要在我发出请求时传递客户端证书,并且还需要将我的 IP 地址列入白名单。
商业 API 已将我从 Azure 中的应用服务/属性/传出和虚拟 IP 地址获得的 IP 列入白名单
我已将我的客户端证书文件 (.p12) 添加到我的解决方案中的文件夹中,并且在检查上传到 azure 的文件时,我也可以在那里看到它。
使用 RestSharp,我的请求看起来像:
private string RequestToBv(string pXml)
{
X509Certificate2 cert = new X509Certificate2(bvCertificatePath, bvCertificatePassword);
var client = new RestClient(mXmlApiUrl); //mXmlApiUrl = url to endpoint
client.Timeout = -1;
client.ClientCertificates = new X509CertificateCollection() { cert };
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/xml");
request.AddParameter("application/xml", pXml, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
if (response.StatusCode == HttpStatusCode.OK)
{ …
Run Code Online (Sandbox Code Playgroud)