C# 使用c读取HTML页面时出现异常

C# 使用c读取HTML页面时出现异常,c#,httpresponse,httpwebresponse,system.net.webexception,system.net.httpwebrequest,C#,Httpresponse,Httpwebresponse,System.net.webexception,System.net.httpwebrequest,我正在使用以下代码阅读HTML代码: string urlAddress = "http://google.com"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if

我正在使用以下代码阅读HTML代码:

            string urlAddress = "http://google.com";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = null;
                if (response.CharacterSet == null)
                    readStream = new StreamReader(receiveStream);
                else
                    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                string data = readStream.ReadToEnd();
                response.Close();
                readStream.Close();
            }
但我有一个例外:

The remote server returned an error: (407) Proxy Authentication Required
此外,我还对app.config文件进行了更改:

 <system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>
但仍然得到同样的错误


但是,当我在IE中打开和翻页时,它会在不询问任何凭据的情况下打开。

如果您想下载google页面,请使用此代码

  using (WebClient web = new WebClient())
     {
          string d=   web.DownloadString("http://google.com");
     }

当我使用Google spider进行一些搜索时,我实际上必须实现一个web浏览器控件,并使用它来呈现结果,看起来像是“人”。通过这种方式,所有请求都可以被计时并呈现到一个页面上,尤其是使用HttpWebRequest无法呈现的AJAX内容。这很不方便,但100%有效。

你尝试过这个吗:看起来它不是在阅读google.com,但当我尝试不同的url时,它是有效的。但是很奇怪:0/当然很奇怪!!!: