C# 带有SSL的Httpclient在Visual studio 2015\或我的笔记本电脑上工作,但在windows server 2012上不工作

C# 带有SSL的Httpclient在Visual studio 2015\或我的笔记本电脑上工作,但在windows server 2012上不工作,c#,.net,ssl,C#,.net,Ssl,我有一个简单的应用程序,它基本上是使用HttpClient将(Postasnyc)消息发送到RESTApi。Net框架是.NET4.5.2。这段代码在mylatop(WIndows 7)中运行良好,但不是在WIndows server 2012中。我尝试了不同的windows服务器,除了我的笔记本电脑以外,其他任何地方都没有。但是SOAPUI在同一台服务器上工作(将.pfx用于SSL,从实际证书创建)。这是一个毫无线索的问题 注意:我已确保服务器上安装了证书 我尝试了以下方法 1.确保中间没有防

我有一个简单的应用程序,它基本上是使用HttpClient将(Postasnyc)消息发送到RESTApi。Net框架是.NET4.5.2。这段代码在mylatop(WIndows 7)中运行良好,但不是在WIndows server 2012中。我尝试了不同的windows服务器,除了我的笔记本电脑以外,其他任何地方都没有。但是SOAPUI在同一台服务器上工作(将.pfx用于SSL,从实际证书创建)。这是一个毫无线索的问题

注意:我已确保服务器上安装了证书

我尝试了以下方法 1.确保中间没有防火墙 2.设置http客户端的超时 3.ServicePointManager.CertificatePolicy=new MyPolicy();-没用 4.wait client.PostAsync(objSearch.Resource,content).configurewait(false);-没有帮助

注意:我已经浏览了很多论坛,尝试了几乎所有的建议

下面给出了代码片段

WebRequestHandler handler = new WebRequestHandler();

X509Certificate2 certificate = GetCertificateFromStore(); // getting the correct certs in server as well.

handler.ClientCertificates.Add(certificate);

handler.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);

        try
        {

            using (var client = new HttpClient(handler))
            {
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls |  SecurityProtocolType.Tls11; 
                client.BaseAddress = new Uri(objSearch.url);
                //client.MaxResponseContentBufferSize = 2147483647;
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                // HTTP GET
                //MessageBox.Show("Ready To post");
                // client.Timeout = TimeSpan.FromSeconds(10); - didnt work
                var response = await client.PostAsync(objSearch.Resource, content);
错误消息。System.Net.Http.HttpRequestException:发生错误 发送请求时。-->System.Net.WebException:异常 基础连接已关闭:服务器上发生意外错误 发送。-->System.IO.IOException:无法从中读取数据 传输连接:连接尝试失败,因为 关联方在一段时间后未作出适当回应,或 建立的连接失败,因为连接的主机无法连接 回应。-->

System.Net.Sockets.SocketException:连接尝试失败 因为关联方在一段时间后未作出适当回应 时间,或建立的连接失败,因为连接的主机已 没有回应

位于System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)

位于System.Net.Sockets.NetworkStream.EndRead(IAsyncResult 异步(结果)

---内部异常堆栈跟踪的结束---at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)

在System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)中

位于System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)

---内部异常堆栈跟踪的结束---at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult、TransportContext和context)位于 System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)--内部异常堆栈跟踪的结束---

在 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务 任务)在 System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务 (任务)

在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中

在RIBS.AccountService.pdfintegator.d_u1.MoveNext()中

在RIBS.AccountService.pdfintegator.d_u1.MoveNext()中

C:\Users\311827364\Source\Repos\RIBS\u Net\Solution\RIBS.AccountService\pdfintegator.cs:line 142---内部异常堆栈跟踪的结束---at System.Threading.Tasks.Task.ThrowifeException(布尔值 includeTaskCanceledExceptions)

位于System.Threading.Tasks.Task`1.GetResultCore(布尔值 waitCompletionNotification)

在System.Threading.Tasks.Task`1.get_Result()中

在RIBS.AccountService.pdfstatementinpl.GetStatementList(字符串 strAccountNumber、字符串Transit、字符串accType、字符串strResource、, 字符串stStartDate,字符串stEndDate)输入

C:\Users\311827364\Source\Repos\RIBS\u Net\Solution\RIBS.AccountService\pdfstatemenimpl.cs:line 23 --->(内部异常#0)System.InvalidOperationException:无法从Ondemand获取语句列表

在中的RIBS.AccountService.pdfintegator.d_uu1.MoveNext()处 C:\Users\311827364\Source\Repos\RIBS\u Net\Solution\RIBS.AccountService\pdfintegator.cs:line
142您是如何实现ValidateRemoteCertificate的?你检查防火墙设置了吗?这也可能会阻止正确的结果。是否有代理服务器在起作用?我以前在需要代理服务器的地方遇到过问题;我对任何输入都说是。Hi Client,我使用的URL是F5(负载平衡器)URL,其中F5被实现为传递,这意味着在F5级别没有SSL检查。