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

时间:2017-03-22 23:15:32

标签: asp.net ssl httpwebrequest

我使用HttpWebRequest从ASP.net 2.0 Web应用程序使用ssl V3连接到java webservice。当我调用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();

感谢任何帮助。在此先感谢!!

2 个答案:

答案 0 :(得分:2)

我找到了答案。看起来我尝试连接的web服务使用更高版本。我不得不更新我的应用程序以使用.net framework 4.5来执行以下操作:

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

答案 1 :(得分:1)

我也在处理这个错误,但它只发生在我的Windows XP机器上。 您是否在Windows 7或更高版本中尝试过它?