Re: How to judge whether content type is truly "text/html"?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




Vadym Stetsyak 写道:

Hello, Morgan!

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.
I agree.
It happens to me to handle some un-normal situation:p


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...
The problem is the encoding.
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

.



Relevant Pages

  • RE: WSE 2.0 encoding error
    ... Microsoft MSDN Online Support Lead ... Subject: WSE 2.0 encoding error ... giberish from server service since it is output hebrew encoding response, ...
    (microsoft.public.dotnet.xml)
  • Re: WSE 2.0 and french text
    ... My Web Service is sending a response encoding with ISO-8859-1. ... If i change the settings of my HTTP Server in order to send a response ... >> These Web Services retrieve datas from an Oracle database. ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • Re: Byte[] Problemchen (Socket.Response)
    ... Möglichkeiten Request zu senden bzw. eine Response zu konstruieren. ... Connection-Close oder Content-Legth (bzw. chuncked encoding), ... Prev by Date: ... Next by Date: ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Help needed with python unicode cgi-bin script
    ... Hi Martin, thanks for your response. ... I don't know for sure the encoding of the file. ... perhaps run the CGI script in a web server, and pointed your web browser ... Firefox says the page is UTF8. ...
    (comp.lang.python)
  • Re: XMLHTTP and accented characters
    ... >> on the encoding and the charset used. ... >> ASP documents as UTF-8 and indicate the encoding as the code page ... Please reply to the newsgroup. ... quicker response by posting to the newsgroup. ...
    (microsoft.public.scripting.jscript)