views:

41

answers:

2

I need to call a webpage, but have my webclient act like it doesn't support HTML4.0, but only HTML3.2.

Is it possible to do this? Perhaps with a different user-agent or some header I'm unaware of?

Thanks.

This is related to this problem:

http://stackoverflow.com/questions/3662457/ssrs-2008-force-html3-2

+4  A: 

The WebClient Class implements HTTP. It contains nothing related to HTML.

If the website you're retrieving serves different content depending on the HTTP "User-Agent" header, you can set this header as follows:

WebClient client = new WebClient();

client.Headers.Add("user-agent",
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

Which value you need to specify depends, of course, on the website.

dtb
@dtb, I know it doesn't know about the HTML it's retrieving, but I need it to act like it can't accept html4.0. I'm calling a server that does some sort of sniffing and supposedly changes it's content based on what the browser supports. So, I guess I need a user-agent that came from a browser that didn't support HTML4.0. And IE6 isn't old enough
Chad
@dtb, I've tried going with the user-agent "Mozilla/1.22 (compatible; MSIE 2.0; Windows 3.1)" (actually several, that's just the oldest I've tried) and I'm still getting html4.0 content... Any other ideas?
Chad
@Chad: How do you know that the website is actually serving HTML 3.2 content in some cases? Did you use an old web browser or is it pure speculation?
dtb
@dtb, it's SSRS, it's documentation says it will.
Chad
@Chad: "The HTML 3.2 format in the HTML rendering extension is discontinued in this release. The rendering extension is no longer included in a Reporting Services installation." http://msdn.microsoft.com/en-us/library/ms144231.aspx
dtb
@dtb, It's nice their documentation is consistent. "Format: Specifies the format in which to render a report. Common values include HTML3.2, HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, and NULL." http://msdn.microsoft.com/en-us/library/ms152835.aspx But there is another page, which I can't find, which says that if HTML4.0 is not supported, it will fallback to 3.2
Chad
+1  A: 

WebClient has no notion of what kind of HTML it is downloading. If the site you're accessing is doing some sort of sniffing, use HttpWebRequest and set the UserAgent property to some really old browser.

You can set the User-Agent header using WebClient as well, but you have to set the header directly as there's no associated property.

John Sheehan