【问题标题】:Connection timed out when going through proxy通过代理时连接超时
【发布时间】: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


【解决方案1】:

首先做一个外行检查,因为有时IP无法访问或端口未打开以接收连接,可能是防火墙不允许您的连接。

请访问以下链接,这可以帮助您解决问题:

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

【讨论】:

    猜你喜欢
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 2015-08-14
    • 1970-01-01
    • 2011-08-17
    相关资源
    最近更新 更多