C# 正在尝试发送HTTPS请求并获取;接收时发生意外错误";

C# 正在尝试发送HTTPS请求并获取;接收时发生意外错误";,c#,https,ssl-certificate,C#,Https,Ssl Certificate,我们目前有一个第三方客户机,我们也发送一些XML。然后我们得到下载文件的回报。我首先必须生成一个CSR,我们在其中给了他们一个pb7文件,作为回报,我将其安装在服务器上并与私钥配对。我有一个C#测试,当试图用GetRequestStream发送POST请求时,它会不断失败。我尝试将其设置为TLs 1.2,并确保在服务器上启用了它。端口443已打开,正在服务器上侦听。我想要的证书已经发送了,所以我不知道为什么我不能通过申请。导致问题的代码如下所示。WebResponse是ReceiveFailur

我们目前有一个第三方客户机,我们也发送一些XML。然后我们得到下载文件的回报。我首先必须生成一个CSR,我们在其中给了他们一个pb7文件,作为回报,我将其安装在服务器上并与私钥配对。我有一个C#测试,当试图用GetRequestStream发送POST请求时,它会不断失败。我尝试将其设置为TLs 1.2,并确保在服务器上启用了它。端口443已打开,正在服务器上侦听。我想要的证书已经发送了,所以我不知道为什么我不能通过申请。导致问题的代码如下所示。WebResponse是ReceiveFailure。我还做了wireshark跟踪,我可以看到它通过http从他们的服务器连接到我们的服务器,但当我们的服务器通过tcp连接到他们的服务器时,它立即失败

private const string DTTM_PATTERN = "yyyy-MM-ddTHH:mm:ss.FZ";
        private const string SS_API_URL = "https://www.example.com/v_6?id=";
        private static string Proxy_Address = "My.Domain.Com";

        static void Main(string[] args)
        {

        var messageID = Guid.NewGuid().ToString().Replace("-", "");
           var currDate = DateTime.UtcNow.ToString(DTTM_PATTERN);



            string xmlMessage =
          @"The XML is here"
            string url = SS_API_URL + messageID;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection collection = 
            store.Certificates.Find(X509FindType.FindBySubjectName, "my.certifcate.com", true);      
            request.ClientCertificates = collection;
            byte[] requestInFormOfBytes = 
            System.Text.Encoding.ASCII.GetBytes(xmlMessage);
            request.Method = "POST";
            request.ContentType = "text/xml;charset=utf-8";
            request.ContentLength = requestInFormOfBytes.Length;
            request.Proxy = new WebProxy(Proxy_Address, 443); 
            request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            try
            {
               //The error appears here on request.GetRequestStream
                using (var requestStream = request.GetRequestStream())
                {
                    requestStream.Write(requestInFormOfBytes, 0, requestInFormOfBytes.Length);
                    requestStream.Close();
                }

                }
            catch (WebException webExcp)
            {
                // If you reach this point, an exception has been caught.  
                Console.WriteLine("A WebException has been caught.");
                // Write out the WebException message.  
                Console.WriteLine(webExcp.ToString());
                // Get the WebException status code.  
                WebExceptionStatus status = webExcp.Status;
                // If status is WebExceptionStatus.ProtocolError,   
                //   there has been a protocol error and a WebResponse   
                //   should exist. Display the protocol error.  
                if (status == WebExceptionStatus.ProtocolError)
                {
                    Console.Write("The server returned protocol error ");
                    // Get HttpWebResponse so that you can check the HTTP status code.  
                    HttpWebResponse httpResponse = (HttpWebResponse)webExcp.Response;
                    Console.WriteLine((int)httpResponse.StatusCode + " - "
                       + httpResponse.StatusCode);
                }
            }

几个月前,我在一个已经运行了几个月的服务中遇到了这个错误。。问题在于Tls12证书,我使用的确切代码是:
ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3是的,这似乎是常见的解决方案,但遗憾的是,我已经尝试了,但它不起作用?这似乎是另一个解决方案。我也尝试了两种方法,但都没有成功。1)设置自己的HTTPS服务器(甚至是模拟服务器),这样您就可以在没有第三方的情况下测试它。如果你碰巧犯了错误,这可以很容易地排除常见的错误。2) 学习Wireshark等工具,以便轻松捕获和分析SSL/TLS握手。实际的数据包可以告诉我们很多可能的原因。几个月前,我在一个已经运行了几个月的服务中遇到了这个错误。。问题在于Tls12证书,我使用的确切代码是:
ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3是的,这似乎是常见的解决方案,但遗憾的是,我已经尝试了,但它不起作用?这似乎是另一个解决方案。我也尝试了两种方法,但都没有成功。1)设置自己的HTTPS服务器(甚至是模拟服务器),这样您就可以在没有第三方的情况下测试它。如果你碰巧犯了错误,这可以很容易地排除常见的错误。2) 学习Wireshark等工具,以便轻松捕获和分析SSL/TLS握手。实际的数据包可以说明很多可能的原因。