c# - 系统.Net.WebException : The underlying connection was closed: The connection was closed unexpectedly

标签 c# asp.net

我正在编写一个 .NET 应用程序,它应该将数据发布到另一个 .NET 应用程序。 我使用下面的代码来请求登录页面

WebProxy proxy = new WebProxy("http://proxy:80/", true);
HttpWebRequest webRequest = WebRequest.Create(LOGIN_URL) as HttpWebRequest;
//proxy.Credentials = new NetworkCredential("myusername", "mypassword", "domain"); 
// webRequest.Proxy = proxy;
webRequest.Proxy = WebRequest.DefaultWebProxy;

StreamReader responseReader = new StreamReader
                                  (webRequest.GetResponse().GetResponseStream());
string responseData = responseReader.ReadToEnd();

但是在这一行失败了

StreamReader responseReader = new StreamReader
                                  (webRequest.GetResponse().GetResponseStream());

错误信息:

System.Net.WebException: The underlying connection was closed: The connection was 
                         closed unexpectedly.

最佳答案

就我而言,这解决了问题:

System.Net.ServicePointManager.Expect100Continue = false;

以上都不是。

关于c# - 系统.Net.WebException : The underlying connection was closed: The connection was closed unexpectedly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1459475/

相关文章:

c# - 调整窗口大小并保持内容比例

java - 这个 Java 代码在 C# 中相当于什么? (设置请求实体)

c# - 使用手动创建的表单例份验证票设置超时

javascript - 获取 Web 服务的进度百分比

javascript - Gridview TH 中未引发 jQuery 事件

c# - 检查两个数字中每个对应数字的总和是否相同?

c# - 从服务器端调用 Javascript 函数

C#,运算符 '??' 不能应用于类型 'decimal' 和 'decimal' 的操作数

c# - p4.net 无法连接 Perforce

javascript - 使用 jQuery 时如何在 ASP.NET 中同时触发 OnClick 和 OnClientClick 事件?