C# Web 请求异常 : The underlying connection was closed: An unexpected error occurred on a receive

标签 c# httpwebrequest webrequest

通常情况下,此代码完全可以正常工作,但我在客户 PC 上有一个实例抛出此异常。我们根本无法复制。与主题一样,我得到的异常是“基础连接已关闭:接收时发生意外错误。”我已经对此进行了研究,但我所能找到的只是将 KeepAlive 设置为 false,我已经完成了。这通常是一个 SSL 连接,但我让客户尝试通过标准 http 建立相同的连接,我们得到了相同的结果。

这通常是一个超快的网络请求,userinfo 类有大约 10 个字符串元素,并且在一个微小的 MySQL 查询后以大约 100 个字符的字符串响应。所以我不认为这是超时的事情。

有什么想法吗?

public static string HitServer(string url)
        {

            if (UserInfo.Instance == null) return "";
            //Request update XML path
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.KeepAlive = false;
            req.Method = "POST";
            req.ContentType = "xml/text";
            using (Stream reqStream = req.GetRequestStream())
            {
                XmlSerializer s = new XmlSerializer(typeof(UserInfo));
                s.Serialize(reqStream, UserInfo.Instance);
            }

            WebResponse response = req.GetResponse();
            Stream responseStream = response.GetResponseStream();
            StreamReader sr = new StreamReader(responseStream);
            return sr.ReadToEnd();
        }

最佳答案

在尝试了 HTTP 协议(protocol)更改、Expect100contine、keepalive 和一些其他请求参数等各种修复之后,我不得不切换到非 SSL 并仅通过此连接加密密码。

这不是最理想的修复,但必须完成。似乎某些 PC 上的某些东西会阻止来 self 们应用程序的 SSL 连接。这是通过使用我们软件内置的浏览器 View 来测试的,以尝试在安全服务器上加载图像 - 但失败了。

关于C# Web 请求异常 : The underlying connection was closed: An unexpected error occurred on a receive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6922628/

相关文章:

c# - 将 XML 反序列化为嵌套对象列表,返回计数 0

c# - 如何正确使用BindIPEndPointDelegate?

c# - CookieContainer 处理路径(谁吃了我的 cookie?)

c# - WebRequest 正在检索与浏览器不同的 HTML

ios - 通过iOS App登录网页

javascript - asp.net按钮-JS点击不起作用

c# - 锁内锁

c# - 每个程序集一个命名空间?

windows - HttpWebRequest 和 HttpWebResponse 的 C++ 接口(interface)版本

c# - 从 System.Net.WebRequest 获取完整的响应正文