我正在使用下面的代码来阅读 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 中打开和页面时,它会在不询问任何凭据的情况下打开。