閱讀HTML網頁,我使用下面的代碼來讀取HTML代碼:異常而使用C#
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
另外,我還修改了自己的應用程序。配置文件:
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
但仍然收到相同的錯誤。
但是,當我在IE中打開並打開頁面時,它會打開而不詢問任何憑據。
您是否嘗試過: http://stackoverflow.com/questions/11148288/the-remote-server-returned-an-error-407-proxy-authentication-required – adityaswami89 2014-10-17 04:39:36
看起來好像不是在閱讀google.com ,但是當我嘗試不同的網址時,它可以正常工作。奇怪,雖然 – Aquarius24 2014-10-17 04:59:49
:0 /奇怪當然! :) – adityaswami89 2014-10-17 05:02:17