【问题标题】:While debugging this code fragment ,this error occurs调试此代码片段时,出现此错误
【发布时间】:2014-04-03 08:13:12
【问题描述】:

调试此代码片段时,出现此错误(无法连接远程服务器)。我在注释行中显示了错误发生的位置

private static string GetWebText(string url)
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.UserAgent = "A .NET Web Crawler";

        WebResponse response = request.GetResponse();//errors occured here

        Stream stream = response.GetResponseStream();

        StreamReader reader = new StreamReader(stream);
        string htmlText = reader.ReadToEnd();
        return htmlText;
    }

【问题讨论】:

  • 什么是错误堆栈?如果您在组织内使用它,请确保验证您的代理。
  • 如果你使用浏览器访问同一个 url,你会得到什么?
  • 我只是尝试运行我的代码,但它说无法连接远程服务器
  • 可能是关于 Web.Config:forums.asp.net/t/1585771.aspx

标签: c# asp.net .net web-crawler remote-server


【解决方案1】:

您应该尝试找出问题所在,可能是 URL 错误或请求/响应出现问题。为了查看您的应用程序背后的流量,我建议使用Fiddler 来检查幕后发生的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 2019-01-26
    • 2021-12-24
    • 1970-01-01
    相关资源
    最近更新 更多