【发布时间】:2018-10-24 23:06:11
【问题描述】:
此代码在不通过代理服务器时完美运行。它加载所需的网页。当我取消注释一行时,我得到一个错误。
错误信息
"The underlying connection was closed: The connection was closed unexpectedly." System.Exception System.Net.WebException
导致错误的一行。
//request.Proxy = new Webproxy("192.157.252.245",80);
通过代理网站或将其设置为本地代理时,我使用的代理可以正常工作。
Uri address = new Uri("http://google.com/");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
////////Add Proxy
//request.Proxy = new Webproxy("192.157.252.245",80);
////////End Add Proxy
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader streamReader = new StreamReader(response.GetResponseStream());
string strReaderXML = streamReader.ReadToEnd();
}
【问题讨论】:
-
代理和类似问题首先是网络问题,不是编程问题。这些类不关心另一端是否在同一台计算机、同一路由器或 Voyager 2 探测器上。
-
我相信这是c#中的设置问题。
-
你是对的,这是网络设置的问题。因此不是编程问题,而是网络问题。
标签: c# networking proxy network-programming httpwebrequest