WebRequest not working

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Can anyone tell me why the below code to downoalds a web page doesn't work
and it only downloads the below single html comment tag.
("\n\n<!-- Request Elapsed Time = 15 ms -->\n\n")?

It doesnt happen to all URLs just the one is this sample. Is there some
kind of redirect or something happend that the request is not following?

WebResponse objResponse;
WebRequest objRequest =
WebRequest.Create("http://www.bungie.net/games/halo2/page.aspx?section=FAQInfo&subsection=playlists&page=1");
objRequest.Method = "GET";
objRequest.Timeout = 120000; // 120 sec.'
objResponse = objRequest.GetResponse();
System.IO.StreamReader sr = new
StreamReader(objResponse.GetResponseStream());
string HTML = sr.ReadToEnd();
sr.Close();
 
Bill said:
Can anyone tell me why the below code to downoalds a web page doesn't
work and it only downloads the below single html comment tag.
("\n\n<!-- Request Elapsed Time = 15 ms -->\n\n")?

It doesnt happen to all URLs just the one is this sample. Is there
some kind of redirect or something happend that the request is not
following?

WebResponse objResponse;
WebRequest objRequest =
WebRequest.Create("http://www.bungie.net/games/halo2/page.aspx?section
=FAQInfo&subsection=playlists&page=1"); objRequest.Method = "GET";
objRequest.Timeout = 120000; // 120 sec.'
objResponse = objRequest.GetResponse();
System.IO.StreamReader sr = new
StreamReader(objResponse.GetResponseStream());
string HTML = sr.ReadToEnd();
sr.Close();

I guess the site evaluates the User-Agent header to detect the browser
type and version. Try adding a User-Agent header string, e.g.
"Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.7.7)
Gecko/20050414 Firefox/1.0.3" for a German version Firefox.

Cheers,
 
Back
Top