Re: How to judge whether content type is truly "text/html"?
- From: "Morgan Cheng" <morgan.chengmo@xxxxxxxxx>
- Date: 21 Sep 2006 09:45:37 -0700
Vadym Stetsyak 写道:
Hello, Morgan!I agree.
MC> I know that HttpWebRequest.GetResponse() generates a HttpWebResonse.
MC> The response has one ContentType property. But the property is just
MC> decided by http response header. It is possible that the content is
MC> actually HTML, while the ContentType is "image/jpeg".
If you're talking to "well-behaved" web server, then it gives you the content
from the set you've specified in the Accept header.
It happens to me to handle some un-normal situation:p
The problem is the encoding.
MC> Is there any effective way to judge whether the response type is truly
MC> "text"?
MC> I have a idea to read the first several bytes of the response stream;
MC> and check whether they are real displayable characters. But, they can
MC> be any kind of Encoding. Should I try all kinds of Encoding?
IMO there is no good way how verify if it is "text".
As a workaround you can check the response content for the subset of printable
characters...
However, html lang are in English which is 33-127 in most of Encoding.
Perhaps try to parse some html tag works.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
.
- References:
- How to judge whether content type is truly "text/html"?
- From: Morgan Cheng
- How to judge whether content type is truly "text/html"?
- Prev by Date: Re: There has to be a better way to work withat string chars
- Next by Date: Re: How to judge whether content type is truly "text/html"?
- Previous by thread: Re: How to judge whether content type is truly "text/html"?
- Next by thread: Re: How to judge whether content type is truly "text/html"?
- Index(es):
Relevant Pages
|