从 ssl webservice 获取请求流时,从传输流收到意外的 EOF 或 0 字节

ptn*_*n77 7 asp.net ssl httpwebrequest

我正在使用 HttpWebRequest 从 ASP.net 2.0 Web 应用程序使用 ssl V3 连接到 java web 服务。当我调用 GetRequestStream 时,收到错误“从传输流接收到意外的 EOF 或 0 字节”。我尝试添加 ServerCertificateValidationCallback 并返回 true 以忽略服务器证书的任何问题并将安全协议设置为 ssl3 或 tls。我确保从网站下载了证书,并将其根证书链安装在 localMachine 存储位置的受信任根中。我还将该网站的证书安装到 LocalMachine 的个人和受信任人员存储中。然而,我仍然遇到同样的错误。我不确定此时还可以尝试什么。

以下是我连接到网络服务的代码:

 HttpWebRequest myReq =
                (HttpWebRequest)WebRequest.Create(Url);
            myReq.Method = "POST";
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

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

            byte [] lbPostBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(sb.ToString());
            myReq.ContentType = "text/xml; charset=utf-8";
            myReq.ContentLength = lbPostBuffer.Length;
            myReq.Accept = "text/xml";

            Stream loPostData = myReq.GetRequestStream();
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。提前致谢!!

ptn*_*n77 10

我找到了答案。看起来我尝试连接的 Web 服务正在使用更高的 tls 版本。我必须更新我的应用程序以使用 .net Framework 4.5 才能执行以下操作:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
Run Code Online (Sandbox Code Playgroud)