I'm working with ContentType class to parse content type (type + encoding) of a webpage.
I'm noticed that this input fails (FormatException):
text/html; charset: windows-1255
This is the code:
using System.Net.Mime;
//...
ContentType ct;
try
{
ct = new ContentType(content_type);
}
catch (FormatException ex)
{
return eFileType.Unknown;
}
Why it's throwing FormatException?
The documentation on the
ContentTypeconstructor states that it throws anFormatExceptionif:In this case, it is because
charset:is not supported,charset=is:This behavior is according to the W3C specs on content type headers, that states that a parameter must follow this format:
So an equals sign is the documented separator between
attributeandvalue.