0

I am using below code to read HTML code:

            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();
            }

However I am getting exception:

The remote server returned an error: (407) Proxy Authentication Required

Also, I have made changes to my app.config file:

 <system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>

but still getting the same error.

However, when I open and page in IE, it opens without asking any credentials.

Aquarius24
  • 1,806
  • 6
  • 33
  • 61

2 Answers2

0

Use this code if you want download google page

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

When I did my Google spider to get some searches, I actually had to implement a web browser control and use it to render results and appear to be 'human'. This way all requests could be timed and rendered to a page -- especially AJAX stuff which you can't render using HttpWebRequest. It is inconvenient, but 100% working.

Andrew
  • 7,619
  • 13
  • 63
  • 117