我正在编写一个 .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/